Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { logger } from '~/utils/logger';

class ErrorBoundary extends React.Component<{
fallback: React.ReactNode;
Expand All @@ -13,7 +14,7 @@ class ErrorBoundary extends React.Component<{
}

static getDerivedStateFromError(error: Error) {
console.error('Error in component:', error);
logger.error('Error in component:', error);
return { hasError: true };
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useState } from 'react';
import { useQuery } from '@tanstack/react-query';
import { useConfirm } from '~/contexts/ConfirmContext';
import { useConfirm } from '~/hooks/useConfirm';
import { isLoggedIn as checkIsLoggedIn, showLoginPrompt } from '~/utils/loginPrompt';
import { toast } from '~/utils/toast';
import { logger } from '~/utils/logger';
import {
getComments,
createComment,
Expand Down Expand Up @@ -125,7 +126,7 @@ const Comments = (props: CommentsProps) => {
toast.error('댓글 정보를 불러오는데 실패했습니다.');
}
} catch (err) {
console.error('댓글 수정 오류:', err);
logger.error('댓글 수정 오류:', err);
toast.error('댓글 정보를 불러오는 중 오류가 발생했습니다.');
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useRef } from 'react';
import SocialLogin from '~/components/remotes/SocialLogin';
import { logger } from '~/utils/logger';

interface LoginFormProps {
username: string;
Expand Down Expand Up @@ -71,7 +72,7 @@ const LoginForm = ({
}
});
} catch (e) {
console.error('Failed to render hCaptcha:', e);
logger.error('Failed to render hCaptcha:', e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { useState, useEffect, useRef } from 'react';
import { toast } from '~/utils/toast';
import { useConfirm } from '~/contexts/ConfirmContext';
import { useConfirm } from '~/hooks/useConfirm';
import PostEditorWrapper from './PostEditorWrapper';
import PostActions from './components/PostActions';
import PostForm from './components/PostForm';
import SettingsDrawer from './components/SettingsDrawer';
import { getSeries } from '~/lib/api/settings';
import { getPostForEdit } from '~/lib/api/posts';
import { api } from '~/components/shared';
import { logger } from '~/utils/logger';

interface Series {
id: string;
Expand Down Expand Up @@ -127,7 +128,7 @@ const EditPostEditor = ({ username, postUrl }: EditPostEditorProps) => {
return data.body.url;
}
} catch (error) {
console.error('Image upload failed', error);
logger.error('Image upload failed', error);
}
return undefined;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
useRef
} from 'react';
import { toast } from '~/utils/toast';
import { useConfirm } from '~/contexts/ConfirmContext';
import { useConfirm } from '~/hooks/useConfirm';
import PostEditorWrapper from './PostEditorWrapper';
import PostActions from './components/PostActions';
import PostForm from './components/PostForm';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, useEffect } from 'react';
import { logger } from '~/utils/logger';
import { Dialog } from '@blex/ui';
import { getTempPosts, type TempPost } from '~/lib/api/settings';
import { cx } from '~/lib/classnames';
Expand Down Expand Up @@ -35,7 +36,7 @@ const TempPostsPanel = ({
setTempPosts([]);
}
} catch (error) {
console.error('Failed to fetch temp posts:', error);
logger.error('Failed to fetch temp posts:', error);
setTempPosts([]);
} finally {
setIsLoading(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';
import { createTempPost, updateTempPost } from '~/lib/api/posts';

interface AutoSaveData {
Expand Down Expand Up @@ -48,7 +48,7 @@ export const useAutoSave = (data: AutoSaveData, options: UseAutoSaveOptions) =>
});

// Manual save
const manualSave = async () => {
const manualSave = useCallback(async () => {
const currentData = dataRef.current;
const currentOptions = optionsRef.current;

Expand Down Expand Up @@ -98,7 +98,7 @@ export const useAutoSave = (data: AutoSaveData, options: UseAutoSaveOptions) =>
} finally {
setIsSaving(false);
}
};
}, [isSaving]);

// Auto-save effect
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, useEffect } from 'react';
import { logger } from '~/utils/logger';
import { getRelatedPosts, type RelatedPost } from '~/lib/api/posts';

interface RelatedPostsProps {
Expand All @@ -18,7 +19,7 @@ const RelatedPosts = ({ postUrl, username }: RelatedPostsProps) => {
setRelatedPosts(data.body.posts || []);
}
} catch (error) {
console.error('Failed to fetch related posts:', error);
logger.error('Failed to fetch related posts:', error);
} finally {
setIsLoading(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
import { getMediaPath } from '~/modules/static.module';
import { Modal } from '~/components/shared';
import { searchPosts, type SearchResult } from '~/lib/api';
import { logger } from '~/utils/logger';

interface SearchModalProps {
isOpen?: boolean;
Expand Down Expand Up @@ -65,7 +66,7 @@ const SearchModal = ({ isOpen: initialIsOpen = false }: SearchModalProps) => {
setPage(pageNum);
}
} catch (error) {
console.error('Search error:', error);
logger.error('Search error:', error);
} finally {
setIsLoading(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import { toast } from '~/utils/toast';
import { useSuspenseQuery } from '@tanstack/react-query';
import { useConfirm } from '~/contexts/ConfirmContext';
import { useConfirm } from '~/hooks/useConfirm';
import { SettingsHeader } from '../../components';
import { getAccountSettings, updateAccountSettings, deleteAccount } from '~/lib/api/settings';
import { enable2FA, disable2FA, verify2FASetup } from '~/lib/api/auth';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import { toast } from '~/utils/toast';
import { useMutation, useQueryClient, useSuspenseQuery } from '@tanstack/react-query';
import { useConfirm } from '~/contexts/ConfirmContext';
import { useConfirm } from '~/hooks/useConfirm';
import { SettingsHeader } from '../../components';
import { Button, Modal } from '~/components/shared';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
TITLE,
ACTIONS_CONTAINER
} from '~/components/shared';
import { useConfirm } from '~/contexts/ConfirmContext';
import { useConfirm } from '~/hooks/useConfirm';
import {
getForms,
getForm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { toast } from '~/utils/toast';
import { useSuspenseQuery } from '@tanstack/react-query';
import { SettingsHeader } from '../../components';
import { Button } from '~/components/shared';
import { useConfirm } from '~/contexts/ConfirmContext';
import { useConfirm } from '~/hooks/useConfirm';
import { getTelegramStatus, generateTelegramToken, disconnectTelegram as disconnectTelegramAPI } from '~/lib/api/telegram';

const IntegrationSettings = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { toast } from '~/utils/toast';
import { useConfirm } from '~/contexts/ConfirmContext';
import { useConfirm } from '~/hooks/useConfirm';
import {
togglePostVisibility,
togglePostNotice,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useForm } from 'react-hook-form';
import { z } from 'zod';
import { zodResolver } from '@hookform/resolvers/zod';
import { useSuspenseQuery } from '@tanstack/react-query';
import { useConfirm } from '~/contexts/ConfirmContext';
import { useConfirm } from '~/hooks/useConfirm';
import { SettingsHeader } from '../../components';
import { Button, Input, Card } from '~/components/shared';
import { getProfileSettings, updateProfileSettings, uploadAvatar, uploadCover } from '~/lib/api/settings';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
ACTIONS_CONTAINER,
DRAG_HANDLE
} from '~/components/shared';
import { useConfirm } from '~/contexts/ConfirmContext';
import { useConfirm } from '~/hooks/useConfirm';
import {
getSeriesWithUsername,
updateSeriesOrder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SUBTITLE,
ACTIONS_CONTAINER
} from '~/components/shared';
import { useConfirm } from '~/contexts/ConfirmContext';
import { useConfirm } from '~/hooks/useConfirm';
import { getTempPosts, deleteTempPost } from '~/lib/api/settings';

const TempPostsSetting = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import SocialLogin from '~/components/remotes/SocialLogin';

declare global {
Expand Down Expand Up @@ -38,7 +38,7 @@ const Signup = () => {
const captchaRef = useRef<HTMLDivElement>(null);
const widgetIdRef = useRef<string | null>(null);

const renderCaptcha = () => {
const renderCaptcha = useCallback(() => {
if (!captchaRendered && captchaRef.current && window.hcaptcha && window.HCAPTCHA_SITE_KEY) {
try {
widgetIdRef.current = window.hcaptcha.render(captchaRef.current, {
Expand All @@ -54,7 +54,7 @@ const Signup = () => {
// Ignore error
}
}
};
}, [captchaRendered]);

useEffect(() => {
setIsVisible(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, useEffect } from 'react';
import { logger } from '~/utils/logger';
import { getSocialProviders, type SocialProvider } from '~/lib/api';

export const useSocialProviders = () => {
Expand All @@ -14,7 +15,7 @@ export const useSocialProviders = () => {
setProviders(data.body);
}
} catch (error) {
console.error('Failed to load social providers:', error);
logger.error('Failed to load social providers:', error);
}
setLoading(false);
};
Expand All @@ -26,4 +27,4 @@ export const useSocialProviders = () => {
providers,
loading
};
};
};
25 changes: 1 addition & 24 deletions backend/islands/apps/remotes/src/contexts/ConfirmContext.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
import {
createContext,
useContext,
useState,
type ReactNode
} from 'react';
import { Modal } from '@blex/ui';

interface ConfirmOptions {
title: string;
message: string;
confirmText?: string;
cancelText?: string;
variant?: 'default' | 'danger';
}

interface ConfirmContextType {
confirm: (options: ConfirmOptions) => Promise<boolean>;
}

const ConfirmContext = createContext<ConfirmContextType | null>(null);

export const useConfirm = () => {
const context = useContext(ConfirmContext);
if (!context) {
throw new Error('useConfirm must be used within ConfirmProvider');
}
return context;
};
import { ConfirmContext, type ConfirmOptions } from './internal/ConfirmContextDef';

interface ConfirmDialogState extends ConfirmOptions {
isOpen: boolean;
Expand Down
27 changes: 4 additions & 23 deletions backend/islands/apps/remotes/src/contexts/LoginPromptContext.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import {
createContext,
useContext,
useState,
useEffect,
useCallback,
type ReactNode
} from 'react';
import { Modal } from '~/components/shared';

interface LoginPromptContextType {
showLoginPrompt: (action: string) => void;
}

const LoginPromptContext = createContext<LoginPromptContextType | null>(null);

export const useLoginPrompt = () => {
const context = useContext(LoginPromptContext);
if (!context) {
throw new Error('useLoginPrompt must be used within LoginPromptProvider');
}
return context;
};
import { LoginPromptContext } from './internal/LoginPromptContextDef';

interface LoginPromptDialogState {
isOpen: boolean;
Expand All @@ -34,7 +20,7 @@ export const LoginPromptProvider = ({ children }: { children: ReactNode }) => {

const isLoggedIn = !!window.configuration?.user?.username;

const showLoginPrompt = (action: string) => {
const showLoginPrompt = useCallback((action: string) => {
if (isLoggedIn) {
return;
}
Expand All @@ -43,7 +29,7 @@ export const LoginPromptProvider = ({ children }: { children: ReactNode }) => {
isOpen: true,
action
});
};
}, [isLoggedIn]);

// 전역 커스텀 이벤트로 모달 열기 (Alpine.js에서도 사용 가능)
// 중복 방지: 같은 페이지에 여러 island가 있어도 한 번만 모달 표시
Expand Down Expand Up @@ -132,8 +118,3 @@ export const LoginPromptProvider = ({ children }: { children: ReactNode }) => {
</LoginPromptContext.Provider>
);
};

// Export a helper to check login status
export const isUserLoggedIn = (): boolean => {
return !!window.configuration?.user?.username;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createContext } from 'react';

export interface ConfirmOptions {
title: string;
message: string;
confirmText?: string;
cancelText?: string;
variant?: 'default' | 'danger';
}

export interface ConfirmContextType {
confirm: (options: ConfirmOptions) => Promise<boolean>;
}

export const ConfirmContext = createContext<ConfirmContextType | null>(null);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createContext } from 'react';

export interface LoginPromptContextType {
showLoginPrompt: (action: string) => void;
}

export const LoginPromptContext = createContext<LoginPromptContextType | null>(null);
10 changes: 10 additions & 0 deletions backend/islands/apps/remotes/src/hooks/useConfirm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useContext } from 'react';
import { ConfirmContext } from '../contexts/internal/ConfirmContextDef';

export const useConfirm = () => {
const context = useContext(ConfirmContext);
if (!context) {
throw new Error('useConfirm must be used within ConfirmProvider');
}
return context;
};
Loading
Loading