refactor(types): rename AppType to AppId for semantic clarity
Rename `AppType` to `AppId` across the entire frontend codebase to better reflect its purpose as an application identifier rather than a type category. This aligns frontend naming with backend command parameter conventions. Changes: - Rename type `AppType` to `AppId` in src/lib/api/types.ts - Remove `AppType` export from src/lib/api/index.ts - Update all component props from `appType` to `appId` (43 files) - Update all variable names from `appType` to `appId` - Synchronize documentation (CHANGELOG, refactoring plans) - Update test files and MSW mocks BREAKING CHANGE: `AppType` type is no longer exported. Use `AppId` instead. All component props have been renamed from `appType` to `appId`.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useMemo } from "react";
|
||||
import type { AppType } from "@/lib/api";
|
||||
import type { AppId } from "@/lib/api";
|
||||
import type { ProviderCategory } from "@/types";
|
||||
import type { ProviderPreset } from "@/config/providerPresets";
|
||||
import type { CodexProviderPreset } from "@/config/codexProviderPresets";
|
||||
@@ -10,7 +10,7 @@ type PresetEntry = {
|
||||
};
|
||||
|
||||
interface UseApiKeyLinkProps {
|
||||
appType: AppType;
|
||||
appId: AppId;
|
||||
category?: ProviderCategory;
|
||||
selectedPresetId: string | null;
|
||||
presetEntries: PresetEntry[];
|
||||
@@ -21,7 +21,7 @@ interface UseApiKeyLinkProps {
|
||||
* 管理 API Key 获取链接的显示和 URL
|
||||
*/
|
||||
export function useApiKeyLink({
|
||||
appType,
|
||||
appId,
|
||||
category,
|
||||
selectedPresetId,
|
||||
presetEntries,
|
||||
@@ -53,12 +53,7 @@ export function useApiKeyLink({
|
||||
}, [selectedPresetId, presetEntries, formWebsiteUrl]);
|
||||
|
||||
return {
|
||||
shouldShowApiKeyLink:
|
||||
appType === "claude"
|
||||
? shouldShowApiKeyLink
|
||||
: appType === "codex"
|
||||
? shouldShowApiKeyLink
|
||||
: false,
|
||||
shouldShowApiKeyLink: appId === "claude" ? shouldShowApiKeyLink : appId === "codex" ? shouldShowApiKeyLink : false,
|
||||
websiteUrl: getWebsiteUrl,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useMemo } from "react";
|
||||
import type { AppType } from "@/lib/api";
|
||||
import type { AppId } from "@/lib/api";
|
||||
import type { CustomEndpoint } from "@/types";
|
||||
import type { ProviderPreset } from "@/config/providerPresets";
|
||||
import type { CodexProviderPreset } from "@/config/codexProviderPresets";
|
||||
@@ -10,7 +10,7 @@ type PresetEntry = {
|
||||
};
|
||||
|
||||
interface UseCustomEndpointsProps {
|
||||
appType: AppType;
|
||||
appId: AppId;
|
||||
selectedPresetId: string | null;
|
||||
presetEntries: PresetEntry[];
|
||||
draftCustomEndpoints: string[];
|
||||
@@ -27,7 +27,7 @@ interface UseCustomEndpointsProps {
|
||||
* 3. 当前选中的 Base URL
|
||||
*/
|
||||
export function useCustomEndpoints({
|
||||
appType,
|
||||
appId,
|
||||
selectedPresetId,
|
||||
presetEntries,
|
||||
draftCustomEndpoints,
|
||||
@@ -58,7 +58,7 @@ export function useCustomEndpoints({
|
||||
}
|
||||
|
||||
// 3. 当前 Base URL
|
||||
if (appType === "codex") {
|
||||
if (appId === "codex") {
|
||||
push(codexBaseUrl);
|
||||
} else {
|
||||
push(baseUrl);
|
||||
@@ -80,7 +80,7 @@ export function useCustomEndpoints({
|
||||
|
||||
return customMap;
|
||||
}, [
|
||||
appType,
|
||||
appId,
|
||||
selectedPresetId,
|
||||
presetEntries,
|
||||
draftCustomEndpoints,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import type { ProviderCategory } from "@/types";
|
||||
import type { AppType } from "@/lib/api";
|
||||
import type { AppId } from "@/lib/api";
|
||||
import { providerPresets } from "@/config/providerPresets";
|
||||
import { codexProviderPresets } from "@/config/codexProviderPresets";
|
||||
|
||||
interface UseProviderCategoryProps {
|
||||
appType: AppType;
|
||||
appId: AppId;
|
||||
selectedPresetId: string | null;
|
||||
isEditMode: boolean;
|
||||
initialCategory?: ProviderCategory;
|
||||
@@ -16,7 +16,7 @@ interface UseProviderCategoryProps {
|
||||
* 根据选择的预设自动更新类别
|
||||
*/
|
||||
export function useProviderCategory({
|
||||
appType,
|
||||
appId,
|
||||
selectedPresetId,
|
||||
isEditMode,
|
||||
initialCategory,
|
||||
@@ -47,14 +47,14 @@ export function useProviderCategory({
|
||||
const [, type, indexStr] = match;
|
||||
const index = parseInt(indexStr, 10);
|
||||
|
||||
if (type === "codex" && appType === "codex") {
|
||||
if (type === "codex" && appId === "codex") {
|
||||
const preset = codexProviderPresets[index];
|
||||
if (preset) {
|
||||
setCategory(
|
||||
preset.category || (preset.isOfficial ? "official" : undefined),
|
||||
);
|
||||
}
|
||||
} else if (type === "claude" && appType === "claude") {
|
||||
} else if (type === "claude" && appId === "claude") {
|
||||
const preset = providerPresets[index];
|
||||
if (preset) {
|
||||
setCategory(
|
||||
@@ -62,7 +62,7 @@ export function useProviderCategory({
|
||||
);
|
||||
}
|
||||
}
|
||||
}, [appType, selectedPresetId, isEditMode, initialCategory]);
|
||||
}, [appId, selectedPresetId, isEditMode, initialCategory]);
|
||||
|
||||
return { category, setCategory };
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useMemo } from "react";
|
||||
import type { AppType } from "@/lib/api";
|
||||
import type { AppId } from "@/lib/api";
|
||||
import type { ProviderPreset } from "@/config/providerPresets";
|
||||
import type { CodexProviderPreset } from "@/config/codexProviderPresets";
|
||||
import type { ProviderMeta, EndpointCandidate } from "@/types";
|
||||
@@ -10,7 +10,7 @@ type PresetEntry = {
|
||||
};
|
||||
|
||||
interface UseSpeedTestEndpointsProps {
|
||||
appType: AppType;
|
||||
appId: AppId;
|
||||
selectedPresetId: string | null;
|
||||
presetEntries: PresetEntry[];
|
||||
baseUrl: string;
|
||||
@@ -31,7 +31,7 @@ interface UseSpeedTestEndpointsProps {
|
||||
* 4. 预设中的 endpointCandidates
|
||||
*/
|
||||
export function useSpeedTestEndpoints({
|
||||
appType,
|
||||
appId,
|
||||
selectedPresetId,
|
||||
presetEntries,
|
||||
baseUrl,
|
||||
@@ -39,7 +39,7 @@ export function useSpeedTestEndpoints({
|
||||
initialData,
|
||||
}: UseSpeedTestEndpointsProps) {
|
||||
const claudeEndpoints = useMemo<EndpointCandidate[]>(() => {
|
||||
if (appType !== "claude") return [];
|
||||
if (appId !== "claude") return [];
|
||||
|
||||
const map = new Map<string, EndpointCandidate>();
|
||||
// 所有端点都标记为 isCustom: true,给用户完全的管理自由
|
||||
@@ -94,10 +94,10 @@ export function useSpeedTestEndpoints({
|
||||
}
|
||||
|
||||
return Array.from(map.values());
|
||||
}, [appType, baseUrl, initialData, selectedPresetId, presetEntries]);
|
||||
}, [appId, baseUrl, initialData, selectedPresetId, presetEntries]);
|
||||
|
||||
const codexEndpoints = useMemo<EndpointCandidate[]>(() => {
|
||||
if (appType !== "codex") return [];
|
||||
if (appId !== "codex") return [];
|
||||
|
||||
const map = new Map<string, EndpointCandidate>();
|
||||
// 所有端点都标记为 isCustom: true,给用户完全的管理自由
|
||||
@@ -155,7 +155,7 @@ export function useSpeedTestEndpoints({
|
||||
}
|
||||
|
||||
return Array.from(map.values());
|
||||
}, [appType, codexBaseUrl, initialData, selectedPresetId, presetEntries]);
|
||||
}, [appId, codexBaseUrl, initialData, selectedPresetId, presetEntries]);
|
||||
|
||||
return appType === "codex" ? codexEndpoints : claudeEndpoints;
|
||||
return appId === "codex" ? codexEndpoints : claudeEndpoints;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user