fix: 修复一些小问题,优化细节体验 (#352)

This commit is contained in:
ᴀᴍᴛᴏᴀᴇʀ
2025-06-04 21:15:19 +08:00
committed by GitHub
parent c528152986
commit 6226fa7c4d
6 changed files with 144 additions and 97 deletions

View File

@@ -3,7 +3,13 @@
import SettingsIcon from '@lucide/svelte/icons/settings';
import * as Sidebar from '$lib/components/ui/sidebar/index.js';
import { useSidebar } from '$lib/components/ui/sidebar/context.svelte.js';
import { appStateStore, setVideoSourceFilter, clearAll, ToQuery } from '$lib/stores/filter';
import {
appStateStore,
setVideoSourceFilter,
clearAll,
ToQuery,
resetCurrentPage
} from '$lib/stores/filter';
import { type VideoSourcesResponse } from '$lib/types';
import { VIDEO_SOURCES } from '$lib/consts';
@@ -15,7 +21,11 @@
const items = Object.values(VIDEO_SOURCES);
function handleSourceClick(sourceType: string, sourceId: number) {
setVideoSourceFilter(sourceType, sourceId.toString());
setVideoSourceFilter({
type: sourceType,
id: sourceId.toString()
});
resetCurrentPage();
goto(`/${ToQuery($appStateStore)}`);
if (sidebar.isMobile) {
sidebar.setOpenMobile(false);
@@ -52,7 +62,7 @@
<div class="flex-1">
<Sidebar.Group>
<Sidebar.GroupLabel
class="text-muted-foreground mb-2 px-2 text-xs font-medium tracking-wider uppercase"
class="text-muted-foreground mb-2 px-2 text-xs font-medium uppercase tracking-wider"
>
视频来源
</Sidebar.GroupLabel>

View File

@@ -76,22 +76,11 @@
async function handleReset() {
resetting = true;
try {
if (onReset) {
await onReset();
} else {
await api.resetVideo(video.id);
window.location.reload();
}
} catch (error) {
console.error('重置失败:', error);
toast.error('重置失败', {
description: (error as ApiError).message
});
} finally {
resetting = false;
resetDialogOpen = false;
if (onReset) {
await onReset();
}
resetting = false;
resetDialogOpen = false;
}
function handleViewDetail() {

View File

@@ -2,35 +2,35 @@ import { writable } from 'svelte/store';
export interface AppState {
query: string;
currentPage: number;
videoSource: {
key: string;
value: string;
};
type: string;
id: string;
} | null;
}
// 创建应用状态store
export const appStateStore = writable<AppState>({
query: '',
videoSource: {
key: '',
value: ''
}
currentPage: 0,
videoSource: null,
});
export const ToQuery = (state: AppState): string => {
const { query, videoSource } = state;
const params = new URLSearchParams();
if (state.currentPage > 0) {
params.set('page', String(state.currentPage));
}
if (query.trim()) {
params.set('query', query);
}
if (videoSource.key && videoSource.value) {
params.set(videoSource.key, videoSource.value);
if (videoSource && videoSource.type && videoSource.id) {
params.set(videoSource.type, videoSource.id);
}
const queryString = params.toString();
return queryString ? `?${queryString}` : '';
};
// 便捷的设置方法
export const setQuery = (query: string) => {
appStateStore.update((state) => ({
...state,
@@ -38,28 +38,46 @@ export const setQuery = (query: string) => {
}));
};
export const setVideoSourceFilter = (key: string, value: string) => {
export const setVideoSourceFilter = (filter: { type: string; id: string }) => {
appStateStore.update((state) => ({
...state,
videoSource: { key, value }
videoSource: filter,
}));
};
export const clearVideoSourceFilter = () => {
appStateStore.update((state) => ({
...state,
videoSource: { key: '', value: '' }
videoSource: null,
}));
};
export const setCurrentPage = (page: number) => {
appStateStore.update((state) => ({
...state,
currentPage: page,
}));
};
export const resetCurrentPage = () => {
appStateStore.update((state) => ({
...state,
currentPage: 0,
}));
};
export const setAll = (query: string, currentPage: number, videoSource: { type: string; id: string } | null) => {
appStateStore.set({
query,
currentPage,
videoSource,
});
};
export const clearAll = () => {
appStateStore.set({
query: '',
videoSource: { key: '', value: '' }
currentPage: 0,
videoSource: null,
});
};
// 保留旧的接口以兼容现有代码
export const filterStore = writable({ key: '', value: '' });
export const setFilter = setVideoSourceFilter;
export const clearFilter = clearVideoSourceFilter;