mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-30 02:32:09 +08:00
* chore: notice i18n * feat: add script to clean up unused i18n keys * chore: cleanup i18n keys * refactor(i18n/proxies): migrate proxies UI to structured locale keys * chore: i18n for rule module * chore: i18n for profile module * chore: i18n for connections module * chore: i18n for settings module * chore: i18n for verge settings * chore: i18n for theme settings * chore: i18n for theme * chore(i18n): components.home.* * chore(i18n): remove unused i18n keys * chore(i18n): components.profile.* * chore(i18n): components.connection * chore(i18n): pages.logs.* * chore(i18n): pages.*.provider * chore(i18n): components.settings.externalCors.* * chore(i18n): components.settings.clash.* * chore(i18n): components.settings.liteMode.* * chore(i18n): components.settings.backup.* * chore(i18n): components.settings.clash.port.* * chore(i18n): components.settings.misc.* * chore(i18n): components.settings.update.* * chore(i18n): components.settings.sysproxy.* * chore(i18n): components.settings.sysproxy.* * chore(i18n): pages.profiles.notices/components.providers.notices * refactor(notice): unify showNotice usage * refactor(notice): add typed showNotice shortcuts, centralize defaults, and simplify subscriptions * refactor: unify showNotice usage * refactor(notice): unify showNotice API * refactor(notice): unify showNotice usage * chore(i18n): components.test.* * chore(i18n): components.settings.dns.* * chore(i18n): components.home.clashInfo.* * chore(i18n): components.home.systemInfo.* * chore(i18n): components.home.ipInfo/traffic.* * chore(i18n): navigation.* * refactor(i18n): remove pages.* namespace and migrate route texts under module-level page keys * chore(i18n): common.* * chore(i18n): common.* * fix: change error handling in patch_profiles_config to return false when a switch is in progress * fix: improve error handling in patch_profiles_config to prevent requests during profile switching * fix: change error handling in patch_profiles_config to return false when a switch is in progress fix: ensure CURRENT_SWITCHING_PROFILE is reset after config updates in perform_config_update and patch_profiles_config * chore(i18n): restructure root-level locale keys into namespaces * chore(i18n): add missing i18n keys * docs: i18n guide * chore: adjust i18n * refactor(i18n): align UI actions and status labels with common keys * refactor(i18n): unify two-name locale namespaces * refactor(i18n/components): unify locale keys and update component references * chore(i18n): add shared and entities namespaces to all locale files * refactor(i18n): consolidate shared and entity namespaces across features * chore(deps): update npm dependencies to ^7.3.5 (#5310) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * refactor(i18n): migrate shared editor modes and consolidate entities namespaces * tmp * refactor(i18n): flatten locales and move theme/validation strings * docs: CONTRIBUTING_i18n.md * refactor(i18n): restructure feedback and profile namespaces for better organization * refactor(i18n): unify settings locale structure and update references * refactor(i18n): reorganize locale keys for home, proxies, rules, connections, logs, unlock, and tests * refactor(i18n/feedback/layout): unify shared toasts & normalize layout namespace * refactor(i18n): centralize common UI strings in shared * refactor(i18n): flatten headers and unify locale schema * refactor(i18n): consolidate duplicate per-feature translations into shared namespace * refactor(i18n): split locales into per-namespace files * style: lint * refactor(i18n): unify unlock UI translations under tests namespace * feat(i18n): add type-checked translation keys * style: eslint import order * feat(i18n): replace ad-hoc loader with rust-i18n backend bundles * chore(prebuild): remove locale-copy step * fix(i18n, notice): propagate runtime params and update cleanup script path * fix(i18n,notice): make locale formatting idempotent and guard early notice translations * fix(i18n): resolve locale aliases and match OS codes correctly * fix(unlock): use i18next-compatible double-brace interpolation in failure notice * fix(i18n): route unlock error notices through translation keys * fix(i18n): i18n types * feat(i18n): localize upgrade notice for Clash core viewer * fix(notice): ensure runtime overrides apply to prefix translations * chore(i18n): replace literal notices with translation keys * chore(i18n): types * chore(i18n): regen typings before formatting to keep keys in sync * chore(i18n): simply labels * chore(i18n): adjust translation * chore: remove eslint-plugin-i18next * chore(i18n): add/refine Korean translations across frontend scopes and Rust backend (#5341) * chore(i18n): translate settings.json (missed in previous pass) (#5343) * chore(i18n): add/refine Korean translations across frontend scopes and Rust backend * chore(i18n): add/refine Korean translations across frontend scopes and Rust backend * fix(i18n-tauri): quote placeholder-leading value in ko.yml to prevent rust_i18n parse panic * chore(i18n): translate settings.json (forgot to include previously) --------- Co-authored-by: rozan <34974262+thelojan@users.noreply.github.com>
224 lines
5.9 KiB
TypeScript
224 lines
5.9 KiB
TypeScript
import {
|
|
closestCenter,
|
|
DndContext,
|
|
DragEndEvent,
|
|
KeyboardSensor,
|
|
PointerSensor,
|
|
useSensor,
|
|
useSensors,
|
|
} from "@dnd-kit/core";
|
|
import {
|
|
SortableContext,
|
|
sortableKeyboardCoordinates,
|
|
} from "@dnd-kit/sortable";
|
|
import { Box, Button, Grid } from "@mui/material";
|
|
import { emit } from "@tauri-apps/api/event";
|
|
import { nanoid } from "nanoid";
|
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
// test icons
|
|
import apple from "@/assets/image/test/apple.svg?raw";
|
|
import github from "@/assets/image/test/github.svg?raw";
|
|
import google from "@/assets/image/test/google.svg?raw";
|
|
import youtube from "@/assets/image/test/youtube.svg?raw";
|
|
import { BasePage } from "@/components/base";
|
|
import { ScrollTopButton } from "@/components/layout/scroll-top-button";
|
|
import { TestItem } from "@/components/test/test-item";
|
|
import { TestViewer, TestViewerRef } from "@/components/test/test-viewer";
|
|
import { useVerge } from "@/hooks/use-verge";
|
|
|
|
const TestPage = () => {
|
|
const { t } = useTranslation();
|
|
const sensors = useSensors(
|
|
useSensor(PointerSensor),
|
|
useSensor(KeyboardSensor, {
|
|
coordinateGetter: sortableKeyboardCoordinates,
|
|
}),
|
|
);
|
|
const { verge, mutateVerge, patchVerge } = useVerge();
|
|
|
|
// test list
|
|
const testList = useMemo(
|
|
() =>
|
|
verge?.test_list ?? [
|
|
{
|
|
uid: nanoid(),
|
|
name: "Apple",
|
|
url: "https://www.apple.com",
|
|
icon: apple,
|
|
},
|
|
{
|
|
uid: nanoid(),
|
|
name: "GitHub",
|
|
url: "https://www.github.com",
|
|
icon: github,
|
|
},
|
|
{
|
|
uid: nanoid(),
|
|
name: "Google",
|
|
url: "https://www.google.com",
|
|
icon: google,
|
|
},
|
|
{
|
|
uid: nanoid(),
|
|
name: "Youtube",
|
|
url: "https://www.youtube.com",
|
|
icon: youtube,
|
|
},
|
|
],
|
|
[verge],
|
|
);
|
|
|
|
const onTestListItemChange = (
|
|
uid: string,
|
|
patch?: Partial<IVergeTestItem>,
|
|
) => {
|
|
if (patch) {
|
|
const newList = testList.map((x) => {
|
|
if (x.uid === uid) {
|
|
return { ...x, ...patch };
|
|
}
|
|
return x;
|
|
});
|
|
mutateVerge({ ...verge, test_list: newList }, false);
|
|
} else {
|
|
mutateVerge();
|
|
}
|
|
};
|
|
|
|
const onDeleteTestListItem = (uid: string) => {
|
|
const newList = testList.filter((x) => x.uid !== uid);
|
|
patchVerge({ test_list: newList });
|
|
mutateVerge({ ...verge, test_list: newList }, false);
|
|
};
|
|
|
|
const reorder = (list: any[], startIndex: number, endIndex: number) => {
|
|
const result = Array.from(list);
|
|
const [removed] = result.splice(startIndex, 1);
|
|
result.splice(endIndex, 0, removed);
|
|
return result;
|
|
};
|
|
|
|
const onDragEnd = async (event: DragEndEvent) => {
|
|
const { active, over } = event;
|
|
if (over) {
|
|
if (active.id !== over.id) {
|
|
const old_index = testList.findIndex((x) => x.uid === active.id);
|
|
const new_index = testList.findIndex((x) => x.uid === over.id);
|
|
if (old_index < 0 || new_index < 0) {
|
|
return;
|
|
}
|
|
const newList = reorder(testList, old_index, new_index);
|
|
await mutateVerge({ ...verge, test_list: newList }, false);
|
|
await patchVerge({ test_list: newList });
|
|
}
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (!verge) return;
|
|
if (!verge?.test_list) {
|
|
patchVerge({ test_list: testList });
|
|
}
|
|
}, [verge, patchVerge, testList]);
|
|
|
|
const viewerRef = useRef<TestViewerRef>(null);
|
|
const [showScrollTop, setShowScrollTop] = useState(false);
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
|
const scrollToTop = () => {
|
|
containerRef.current?.scrollTo({
|
|
top: 0,
|
|
behavior: "smooth",
|
|
});
|
|
};
|
|
|
|
const handleScroll = (e: any) => {
|
|
setShowScrollTop(e.target.scrollTop > 100);
|
|
};
|
|
|
|
return (
|
|
<BasePage
|
|
full
|
|
title={t("tests.page.title")}
|
|
header={
|
|
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
|
|
<Button
|
|
variant="contained"
|
|
size="small"
|
|
onClick={() => emit("verge://test-all")}
|
|
>
|
|
{t("tests.page.actions.testAll")}
|
|
</Button>
|
|
<Button
|
|
variant="contained"
|
|
size="small"
|
|
onClick={() => viewerRef.current?.create()}
|
|
>
|
|
{t("shared.actions.new")}
|
|
</Button>
|
|
</Box>
|
|
}
|
|
>
|
|
<Box
|
|
ref={containerRef}
|
|
onScroll={handleScroll}
|
|
sx={{
|
|
pt: 1.25,
|
|
mb: 0.5,
|
|
px: "10px",
|
|
height: "calc(100vh - 100px)",
|
|
overflow: "auto",
|
|
position: "relative",
|
|
}}
|
|
>
|
|
<DndContext
|
|
sensors={sensors}
|
|
collisionDetection={closestCenter}
|
|
onDragEnd={onDragEnd}
|
|
>
|
|
<Box sx={{ mb: 4.5 }}>
|
|
<Grid container spacing={{ xs: 1, lg: 1 }}>
|
|
<SortableContext
|
|
items={testList.map((x) => {
|
|
return x.uid;
|
|
})}
|
|
>
|
|
{testList.map((item) => (
|
|
<Grid
|
|
component={"div"}
|
|
size={{ xs: 6, lg: 2, sm: 4, md: 3 }}
|
|
key={item.uid}
|
|
>
|
|
<TestItem
|
|
id={item.uid}
|
|
itemData={item}
|
|
onEdit={() => viewerRef.current?.edit(item)}
|
|
onDelete={onDeleteTestListItem}
|
|
/>
|
|
</Grid>
|
|
))}
|
|
</SortableContext>
|
|
</Grid>
|
|
</Box>
|
|
</DndContext>
|
|
|
|
<ScrollTopButton
|
|
onClick={scrollToTop}
|
|
show={showScrollTop}
|
|
sx={{
|
|
position: "absolute",
|
|
bottom: "20px",
|
|
left: "20px",
|
|
zIndex: 1000,
|
|
}}
|
|
/>
|
|
</Box>
|
|
<TestViewer ref={viewerRef} onChange={onTestListItemChange} />
|
|
</BasePage>
|
|
);
|
|
};
|
|
|
|
export default TestPage;
|