Develop fastapi (#8)

* feat: add side panel with navigation and storage cleaner functionality

* feat: add OpenUrlPage and integrate into app navigation

* feat: 添加 GlobalSnackbar 组件并在多个页面中集成,替换原有 Snackbar 实现

* feat: fix OpenUrl sidebar issue with architecture refactor

- 修复原问题:不再直接替换侧边栏 URL,保持插件导航可见
- 采用配置页 + 查看页分离架构:OpenUrlPage (配置) + OpenUrlViewerPage (查看)
- 支持多个 URL 快捷方式管理(添加/删除)
- 每个 URL 提供两种打开方式:在侧边栏打开 / 在新标签页打开
- 侧边栏查看页使用 iframe 占满全部剩余空间
- 更新 TypeScript 类型定义
- 保留原有混合内容警告检查
- 数据持久化到 Chrome Storage

* refactor: centralized route management - consolidate routing config into single source

* feat: 更换logo

* refactor: code review fixes - security and race condition improvements

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Changes:

- wxt.config.ts: Remove unused `debugger` permission (no code uses it)
- OpenUrlPage.tsx: Fix unreachable showMessage after window.close()
- OpenUrlPage.tsx: Replace unnecessary div wrapper with Fragment to reduce DOM nesting
- OpenUrlViewerPage.tsx: Add URL validation to prevent XSS via javascript:/data: URLs
- OpenUrlViewerPage.tsx: Add sandbox attribute to iframe for security isolation
- OpenUrlViewerPage.tsx: Add error handling for invalid URLs
- StorageCleanerPage.tsx: Fix race condition in handleOptionChange preference saving
- StorageCleanerPage.tsx: Remove unnecessary storage reads when saving preferences (use state directly)
- StorageCleanerPage.tsx: Add timeout cleanup for setTimeout to follow React best practices

* feat: implement drill-down navigation with master-detail dashboard

* feat: enhance dashboard dynamism and refine options UI

* feat: overhaul storage cleaner UI with real-time size estimation and modern aesthetics

* feat: overhaul TimestampPage UI/UX and fix GlobalSnackbar positioning

* fix: decouple popup routing from storage sync and enhance OpenUrlPage UI

* fix: avoid closing sidepanel when opening URL preview from within sidepanel

* fix: enhance storage cleaner size detection and optimize UI layout

* feat: implement independent route persistence and fix standalone window tab identification

* feat(options): add card sorting functionality to dashboard tools
This commit is contained in:
LingandRX
2026-04-16 23:59:11 +08:00
committed by GitHub
parent 9a947d7431
commit bbd0507bcd
9 changed files with 207 additions and 109 deletions
+25 -14
View File
@@ -1,17 +1,19 @@
import { createContext, useContext, useState, useEffect, ReactNode } from 'react';
import type { PageType } from '@/types/storage';
import type { PageType, StorageSchema } from '@/types/storage';
import { storageUtil } from '@/utils/chromeStorage';
import { getDefaultVisibleRoutes } from '@/config/routes';
import { getDefaultVisibleRoutes, getDefaultPageOrder } from '@/config/routes';
interface RouterContextType {
currentPage: PageType;
visiblePages: PageType[];
pageOrder: PageType[];
isLoaded: boolean;
navigateTo: (page: PageType) => void;
navigateLocal: (page: PageType) => void;
syncNavigation: (page: PageType) => void;
goBack: () => void;
setVisiblePages: (pages: PageType[]) => void;
setPageOrder: (pages: PageType[]) => void;
}
const RouterContext = createContext<RouterContextType | null>(null);
@@ -20,34 +22,37 @@ interface RouterProviderProps {
children: ReactNode;
defaultRoute?: PageType;
syncRoute?: boolean;
syncKey?: keyof StorageSchema;
}
export function RouterProvider({
children,
defaultRoute = 'dashboard',
syncRoute = true
syncRoute = true,
syncKey = 'app/currentRoute'
}: RouterProviderProps) {
const [currentPage, setCurrentPage] = useState<PageType>(defaultRoute);
const [visiblePages, setVisiblePages] = useState<PageType[]>(getDefaultVisibleRoutes());
const [pageOrder, setPageOrder] = useState<PageType[]>(getDefaultPageOrder());
const [isLoaded, setIsLoaded] = useState(false);
useEffect(() => {
loadInitialData();
}, []);
}, [syncKey]);
useEffect(() => {
if (isLoaded && syncRoute) {
storageUtil.set('app/currentRoute', currentPage);
storageUtil.set(syncKey, currentPage as any);
}
}, [currentPage, isLoaded, syncRoute]);
}, [currentPage, isLoaded, syncRoute, syncKey]);
// Listen for storage changes if sync is enabled
useEffect(() => {
if (!syncRoute) return;
const handleStorageChange = (changes: { [key: string]: chrome.storage.StorageChange }) => {
if (changes['app/currentRoute']) {
const newRoute = changes['app/currentRoute'].newValue as PageType;
if (changes[syncKey as string]) {
const newRoute = changes[syncKey as string].newValue as PageType;
if (newRoute && newRoute !== currentPage) {
setCurrentPage(newRoute);
}
@@ -56,21 +61,25 @@ export function RouterProvider({
chrome.storage.onChanged.addListener(handleStorageChange);
return () => chrome.storage.onChanged.removeListener(handleStorageChange);
}, [syncRoute, currentPage]);
}, [syncRoute, currentPage, syncKey]);
const loadInitialData = async () => {
try {
const [savedRoute, savedVisiblePages] = await Promise.all([
storageUtil.get('app/currentRoute', defaultRoute),
const [savedRoute, savedVisiblePages, savedPageOrder] = await Promise.all([
storageUtil.get(syncKey, defaultRoute),
storageUtil.get('app/visiblePages', getDefaultVisibleRoutes()),
storageUtil.get('app/pageOrder', getDefaultPageOrder()),
]);
if (savedRoute && syncRoute) {
setCurrentPage(savedRoute);
setCurrentPage(savedRoute as PageType);
}
if (savedVisiblePages) {
setVisiblePages(savedVisiblePages);
}
if (savedPageOrder && savedPageOrder.length > 0) {
setPageOrder(savedPageOrder);
}
} catch (error) {
console.error('Failed to load initial routing data:', error);
} finally {
@@ -87,7 +96,7 @@ export function RouterProvider({
};
const syncNavigation = (page: PageType) => {
storageUtil.set('app/currentRoute', page);
storageUtil.set(syncKey, page as any);
};
const goBack = () => {
@@ -99,12 +108,14 @@ export function RouterProvider({
value={{
currentPage,
visiblePages,
pageOrder,
isLoaded,
navigateTo,
navigateLocal,
syncNavigation,
goBack,
setVisiblePages
setVisiblePages,
setPageOrder
}}
>
{children}