From a7535aab99e734d040f060dc089d04a5e736bada Mon Sep 17 00:00:00 2001 From: "Apple\\Apple" Date: Tue, 3 Jun 2025 16:13:50 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(helpers):=20stand?= =?UTF-8?q?ardize=20file=20naming=20conventions=20and=20improve=20code=20o?= =?UTF-8?q?rganization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rename files to follow camelCase naming convention: • auth-header.js → authUtils.js • other.js → logUtils.js • rehypeSplitWordsIntoSpans.js → textAnimationUtils.js - Update import paths in affected components: • Update exports in helpers/index.js • Fix import in LogsTable.js for logUtils • Fix import in MarkdownRenderer.js for textAnimationUtils - Remove old files after successful migration - Improve file naming clarity: • authUtils.js better describes authentication utilities • logUtils.js clearly indicates log processing functions • textAnimationUtils.js concisely describes text animation functionality This refactoring enhances code maintainability and follows consistent naming patterns throughout the helpers directory. --- web/src/components/LogsTable.js | 2 +- web/src/components/common/markdown/MarkdownRenderer.js | 4 ++-- web/src/components/playground/configStorage.js | 2 +- web/src/constants/index.js | 1 + .../constants.js => constants/playground.constants.js} | 0 web/src/{utils => helpers}/apiUtils.js | 0 web/src/helpers/{auth-header.js => authUtils.js} | 2 +- web/src/helpers/index.js | 6 +++++- web/src/helpers/{other.js => logUtils.js} | 2 +- web/src/{utils => helpers}/messageUtils.js | 2 +- .../textAnimationUtils.js} | 0 web/src/hooks/useApiRequest.js | 6 +++--- web/src/hooks/useDataLoader.js | 6 +++--- web/src/hooks/useMessageActions.js | 4 ++-- web/src/hooks/useMessageEdit.js | 4 ++-- web/src/hooks/usePlaygroundState.js | 4 ++-- web/src/hooks/useSyncMessageAndCustomBody.js | 2 +- web/src/pages/Playground/index.js | 4 ++-- 18 files changed, 28 insertions(+), 23 deletions(-) rename web/src/{utils/constants.js => constants/playground.constants.js} (100%) rename web/src/{utils => helpers}/apiUtils.js (100%) rename web/src/helpers/{auth-header.js => authUtils.js} (99%) rename web/src/helpers/{other.js => logUtils.js} (98%) rename web/src/{utils => helpers}/messageUtils.js (98%) rename web/src/{utils/rehypeSplitWordsIntoSpans.js => helpers/textAnimationUtils.js} (100%) diff --git a/web/src/components/LogsTable.js b/web/src/components/LogsTable.js index 912b198b..e28c22d4 100644 --- a/web/src/components/LogsTable.js +++ b/web/src/components/LogsTable.js @@ -44,7 +44,7 @@ import { stringToColor, } from '../helpers/render'; import Paragraph from '@douyinfe/semi-ui/lib/es/typography/paragraph'; -import { getLogOther } from '../helpers/other.js'; +import { getLogOther } from '../helpers/logUtils.js'; import { IconRefresh, IconSetting, diff --git a/web/src/components/common/markdown/MarkdownRenderer.js b/web/src/components/common/markdown/MarkdownRenderer.js index 870e0b6f..86fdf96e 100644 --- a/web/src/components/common/markdown/MarkdownRenderer.js +++ b/web/src/components/common/markdown/MarkdownRenderer.js @@ -1,6 +1,6 @@ import ReactMarkdown from 'react-markdown'; import 'katex/dist/katex.min.css'; -import 'highlight.js/styles/default.css'; +import 'highlight.js/styles/github.css'; import './markdown.css'; import RemarkMath from 'remark-math'; import RemarkBreaks from 'remark-breaks'; @@ -16,7 +16,7 @@ import { Button, Tooltip, Toast } from '@douyinfe/semi-ui'; import { copy } from '../../../helpers/utils'; import { IconCopy } from '@douyinfe/semi-icons'; import { useTranslation } from 'react-i18next'; -import { rehypeSplitWordsIntoSpans } from '../../../utils/rehypeSplitWordsIntoSpans'; +import { rehypeSplitWordsIntoSpans } from '../../../helpers/textAnimationUtils'; mermaid.initialize({ startOnLoad: false, diff --git a/web/src/components/playground/configStorage.js b/web/src/components/playground/configStorage.js index a4e068cb..91fda88a 100644 --- a/web/src/components/playground/configStorage.js +++ b/web/src/components/playground/configStorage.js @@ -1,4 +1,4 @@ -import { STORAGE_KEYS, DEFAULT_CONFIG } from '../../utils/constants'; +import { STORAGE_KEYS, DEFAULT_CONFIG } from '../../constants/playground.constants'; const MESSAGES_STORAGE_KEY = 'playground_messages'; diff --git a/web/src/constants/index.js b/web/src/constants/index.js index 3f8c0232..9538a7dc 100644 --- a/web/src/constants/index.js +++ b/web/src/constants/index.js @@ -3,3 +3,4 @@ export * from './user.constants'; export * from './toast.constants'; export * from './common.constant'; export * from './model.constants'; +export * from './playground.constants'; diff --git a/web/src/utils/constants.js b/web/src/constants/playground.constants.js similarity index 100% rename from web/src/utils/constants.js rename to web/src/constants/playground.constants.js diff --git a/web/src/utils/apiUtils.js b/web/src/helpers/apiUtils.js similarity index 100% rename from web/src/utils/apiUtils.js rename to web/src/helpers/apiUtils.js diff --git a/web/src/helpers/auth-header.js b/web/src/helpers/authUtils.js similarity index 99% rename from web/src/helpers/auth-header.js rename to web/src/helpers/authUtils.js index f094dd1b..75b4b0df 100644 --- a/web/src/helpers/auth-header.js +++ b/web/src/helpers/authUtils.js @@ -7,4 +7,4 @@ export function authHeader() { } else { return {}; } -} +} \ No newline at end of file diff --git a/web/src/helpers/index.js b/web/src/helpers/index.js index ac164960..fae2c6aa 100644 --- a/web/src/helpers/index.js +++ b/web/src/helpers/index.js @@ -1,4 +1,8 @@ export * from './history'; -export * from './auth-header'; +export * from './authUtils'; export * from './utils'; export * from './api'; +export * from './apiUtils'; +export * from './messageUtils'; +export * from './textAnimationUtils'; +export * from './logUtils'; diff --git a/web/src/helpers/other.js b/web/src/helpers/logUtils.js similarity index 98% rename from web/src/helpers/other.js rename to web/src/helpers/logUtils.js index c5d8c269..ffbe0d74 100644 --- a/web/src/helpers/other.js +++ b/web/src/helpers/logUtils.js @@ -4,4 +4,4 @@ export function getLogOther(otherStr) { } let other = JSON.parse(otherStr); return other; -} +} \ No newline at end of file diff --git a/web/src/utils/messageUtils.js b/web/src/helpers/messageUtils.js similarity index 98% rename from web/src/utils/messageUtils.js rename to web/src/helpers/messageUtils.js index 0ab23315..76412dec 100644 --- a/web/src/utils/messageUtils.js +++ b/web/src/helpers/messageUtils.js @@ -1,4 +1,4 @@ -import { THINK_TAG_REGEX, MESSAGE_ROLES } from './constants'; +import { THINK_TAG_REGEX, MESSAGE_ROLES } from '../constants/playground.constants'; // 生成唯一ID let messageId = 4; diff --git a/web/src/utils/rehypeSplitWordsIntoSpans.js b/web/src/helpers/textAnimationUtils.js similarity index 100% rename from web/src/utils/rehypeSplitWordsIntoSpans.js rename to web/src/helpers/textAnimationUtils.js diff --git a/web/src/hooks/useApiRequest.js b/web/src/hooks/useApiRequest.js index 55688726..5087dc19 100644 --- a/web/src/hooks/useApiRequest.js +++ b/web/src/hooks/useApiRequest.js @@ -6,15 +6,15 @@ import { API_ENDPOINTS, MESSAGE_STATUS, DEBUG_TABS -} from '../utils/constants'; +} from '../constants/playground.constants'; import { buildApiPayload, handleApiError -} from '../utils/apiUtils'; +} from '../helpers/apiUtils'; import { processThinkTags, processIncompleteThinkTags -} from '../utils/messageUtils'; +} from '../helpers/messageUtils'; export const useApiRequest = ( setMessage, diff --git a/web/src/hooks/useDataLoader.js b/web/src/hooks/useDataLoader.js index 2454b007..011a4f7c 100644 --- a/web/src/hooks/useDataLoader.js +++ b/web/src/hooks/useDataLoader.js @@ -1,8 +1,8 @@ import { useCallback, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; -import { API, showError } from '../helpers/index.js'; -import { API_ENDPOINTS } from '../utils/constants'; -import { processModelsData, processGroupsData } from '../utils/apiUtils'; +import { API } from '../helpers/api'; +import { API_ENDPOINTS } from '../constants/playground.constants'; +import { processModelsData, processGroupsData } from '../helpers/apiUtils'; export const useDataLoader = ( userState, diff --git a/web/src/hooks/useMessageActions.js b/web/src/hooks/useMessageActions.js index 84d94d4d..4a0fba69 100644 --- a/web/src/hooks/useMessageActions.js +++ b/web/src/hooks/useMessageActions.js @@ -1,8 +1,8 @@ import { useCallback } from 'react'; import { Toast, Modal } from '@douyinfe/semi-ui'; import { useTranslation } from 'react-i18next'; -import { getTextContent } from '../utils/messageUtils'; -import { ERROR_MESSAGES } from '../utils/constants'; +import { getTextContent } from '../helpers/messageUtils'; +import { ERROR_MESSAGES } from '../constants/playground.constants'; export const useMessageActions = (message, setMessage, onMessageSend, saveMessages) => { const { t } = useTranslation(); diff --git a/web/src/hooks/useMessageEdit.js b/web/src/hooks/useMessageEdit.js index 513f2b32..e91ebae6 100644 --- a/web/src/hooks/useMessageEdit.js +++ b/web/src/hooks/useMessageEdit.js @@ -1,8 +1,8 @@ import { useCallback, useState, useRef } from 'react'; import { Toast, Modal } from '@douyinfe/semi-ui'; import { useTranslation } from 'react-i18next'; -import { getTextContent, buildApiPayload, createLoadingAssistantMessage } from '../utils/messageUtils'; -import { MESSAGE_ROLES } from '../utils/constants'; +import { getTextContent, buildApiPayload, createLoadingAssistantMessage } from '../helpers/messageUtils'; +import { MESSAGE_ROLES } from '../constants/playground.constants'; export const useMessageEdit = ( setMessage, diff --git a/web/src/hooks/usePlaygroundState.js b/web/src/hooks/usePlaygroundState.js index 9e76aa2e..b4b4af47 100644 --- a/web/src/hooks/usePlaygroundState.js +++ b/web/src/hooks/usePlaygroundState.js @@ -1,7 +1,7 @@ import { useState, useCallback, useRef, useEffect } from 'react'; -import { DEFAULT_MESSAGES, DEFAULT_CONFIG, DEBUG_TABS, MESSAGE_STATUS } from '../utils/constants'; +import { DEFAULT_MESSAGES, DEFAULT_CONFIG, DEBUG_TABS, MESSAGE_STATUS } from '../constants/playground.constants'; import { loadConfig, saveConfig, loadMessages, saveMessages } from '../components/playground/configStorage'; -import { processIncompleteThinkTags } from '../utils/messageUtils'; +import { processIncompleteThinkTags } from '../helpers/messageUtils'; export const usePlaygroundState = () => { // 使用惰性初始化,确保只在组件首次挂载时加载配置和消息 diff --git a/web/src/hooks/useSyncMessageAndCustomBody.js b/web/src/hooks/useSyncMessageAndCustomBody.js index 36e5fc67..6f0c19ad 100644 --- a/web/src/hooks/useSyncMessageAndCustomBody.js +++ b/web/src/hooks/useSyncMessageAndCustomBody.js @@ -1,5 +1,5 @@ import { useCallback, useRef } from 'react'; -import { MESSAGE_ROLES } from '../utils/constants'; +import { MESSAGE_ROLES } from '../constants/playground.constants'; export const useSyncMessageAndCustomBody = ( customRequestMode, diff --git a/web/src/pages/Playground/index.js b/web/src/pages/Playground/index.js index 3b890259..b495bc15 100644 --- a/web/src/pages/Playground/index.js +++ b/web/src/pages/Playground/index.js @@ -22,14 +22,14 @@ import { DEFAULT_MESSAGES, MESSAGE_ROLES, ERROR_MESSAGES -} from '../../utils/constants.js'; +} from '../../constants/playground.constants.js'; import { buildMessageContent, createMessage, createLoadingAssistantMessage, getTextContent, buildApiPayload -} from '../../utils/messageUtils.js'; +} from '../../helpers/messageUtils.js'; // Components import {