refactor: refactor graphql

This commit is contained in:
2025-06-12 00:15:26 +08:00
parent b09e9e6aaa
commit 258eeddc74
36 changed files with 680 additions and 612 deletions

View File

@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { useStateRef } from './use-state-ref.ts';
import { useStateRef } from './use-state-ref';
export interface UseDebouncedSkeletonProps {
minSkeletonDuration?: number;
loading?: boolean;

View File

@@ -32,7 +32,6 @@ import { Route as AppPlaygroundGraphqlApiImport } from './routes/_app/playground
import { Route as AppCredential3rdManageImport } from './routes/_app/credential3rd/manage'
import { Route as AppCredential3rdCreateImport } from './routes/_app/credential3rd/create'
import { Route as AppBangumiManageImport } from './routes/_app/bangumi/manage'
import { Route as AppExploreFeedImport } from './routes/_app/_explore/feed'
import { Route as AppExploreExploreImport } from './routes/_app/_explore/explore'
import { Route as AppTasksDetailIdImport } from './routes/_app/tasks/detail.$id'
import { Route as AppSubscriptionsEditIdImport } from './routes/_app/subscriptions/edit.$id'
@@ -169,12 +168,6 @@ const AppBangumiManageRoute = AppBangumiManageImport.update({
getParentRoute: () => AppBangumiRouteRoute,
} as any)
const AppExploreFeedRoute = AppExploreFeedImport.update({
id: '/_explore/feed',
path: '/feed',
getParentRoute: () => AppRouteRoute,
} as any)
const AppExploreExploreRoute = AppExploreExploreImport.update({
id: '/_explore/explore',
path: '/explore',
@@ -306,13 +299,6 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof AppExploreExploreImport
parentRoute: typeof AppRouteImport
}
'/_app/_explore/feed': {
id: '/_app/_explore/feed'
path: '/feed'
fullPath: '/feed'
preLoaderRoute: typeof AppExploreFeedImport
parentRoute: typeof AppRouteImport
}
'/_app/bangumi/manage': {
id: '/_app/bangumi/manage'
path: '/manage'
@@ -510,7 +496,6 @@ interface AppRouteRouteChildren {
AppSubscriptionsRouteRoute: typeof AppSubscriptionsRouteRouteWithChildren
AppTasksRouteRoute: typeof AppTasksRouteRouteWithChildren
AppExploreExploreRoute: typeof AppExploreExploreRoute
AppExploreFeedRoute: typeof AppExploreFeedRoute
}
const AppRouteRouteChildren: AppRouteRouteChildren = {
@@ -521,7 +506,6 @@ const AppRouteRouteChildren: AppRouteRouteChildren = {
AppSubscriptionsRouteRoute: AppSubscriptionsRouteRouteWithChildren,
AppTasksRouteRoute: AppTasksRouteRouteWithChildren,
AppExploreExploreRoute: AppExploreExploreRoute,
AppExploreFeedRoute: AppExploreFeedRoute,
}
const AppRouteRouteWithChildren = AppRouteRoute._addFileChildren(
@@ -542,7 +526,6 @@ export interface FileRoutesByFullPath {
'/auth/sign-in': typeof AuthSignInRoute
'/auth/sign-up': typeof AuthSignUpRoute
'/explore': typeof AppExploreExploreRoute
'/feed': typeof AppExploreFeedRoute
'/bangumi/manage': typeof AppBangumiManageRoute
'/credential3rd/create': typeof AppCredential3rdCreateRoute
'/credential3rd/manage': typeof AppCredential3rdManageRoute
@@ -573,7 +556,6 @@ export interface FileRoutesByTo {
'/auth/sign-in': typeof AuthSignInRoute
'/auth/sign-up': typeof AuthSignUpRoute
'/explore': typeof AppExploreExploreRoute
'/feed': typeof AppExploreFeedRoute
'/bangumi/manage': typeof AppBangumiManageRoute
'/credential3rd/create': typeof AppCredential3rdCreateRoute
'/credential3rd/manage': typeof AppCredential3rdManageRoute
@@ -605,7 +587,6 @@ export interface FileRoutesById {
'/auth/sign-in': typeof AuthSignInRoute
'/auth/sign-up': typeof AuthSignUpRoute
'/_app/_explore/explore': typeof AppExploreExploreRoute
'/_app/_explore/feed': typeof AppExploreFeedRoute
'/_app/bangumi/manage': typeof AppBangumiManageRoute
'/_app/credential3rd/create': typeof AppCredential3rdCreateRoute
'/_app/credential3rd/manage': typeof AppCredential3rdManageRoute
@@ -638,7 +619,6 @@ export interface FileRouteTypes {
| '/auth/sign-in'
| '/auth/sign-up'
| '/explore'
| '/feed'
| '/bangumi/manage'
| '/credential3rd/create'
| '/credential3rd/manage'
@@ -668,7 +648,6 @@ export interface FileRouteTypes {
| '/auth/sign-in'
| '/auth/sign-up'
| '/explore'
| '/feed'
| '/bangumi/manage'
| '/credential3rd/create'
| '/credential3rd/manage'
@@ -698,7 +677,6 @@ export interface FileRouteTypes {
| '/auth/sign-in'
| '/auth/sign-up'
| '/_app/_explore/explore'
| '/_app/_explore/feed'
| '/_app/bangumi/manage'
| '/_app/credential3rd/create'
| '/_app/credential3rd/manage'
@@ -767,8 +745,7 @@ export const routeTree = rootRoute
"/_app/settings",
"/_app/subscriptions",
"/_app/tasks",
"/_app/_explore/explore",
"/_app/_explore/feed"
"/_app/_explore/explore"
]
},
"/404": {
@@ -836,10 +813,6 @@ export const routeTree = rootRoute
"filePath": "_app/_explore/explore.tsx",
"parent": "/_app"
},
"/_app/_explore/feed": {
"filePath": "_app/_explore/feed.tsx",
"parent": "/_app"
},
"/_app/bangumi/manage": {
"filePath": "_app/bangumi/manage.tsx",
"parent": "/_app/bangumi"

View File

@@ -1,15 +0,0 @@
import type { RouteStateDataOption } from '@/infra/routes/traits';
import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/_app/_explore/feed')({
component: FeedRouteComponent,
staticData: {
breadcrumb: {
label: 'Feed',
},
} satisfies RouteStateDataOption,
});
function FeedRouteComponent() {
return <div>Hello "/_app/feed"!</div>;
}

View File

@@ -269,7 +269,7 @@ function CredentialManageRouteComponent() {
}, [handleDeleteRecord, navigate, showPasswords, togglePasswordVisibility]);
const table = useReactTable({
data: data?.credential3rd?.nodes ?? [],
data: useMemo(() => credentials?.nodes ?? [], [credentials]),
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
@@ -335,7 +335,7 @@ function CredentialManageRouteComponent() {
</TableHeader>
<TableBody>
{showSkeleton &&
Array.from(new Array(pagination.pageSize)).map((_, index) => (
Array.from(new Array(10)).map((_, index) => (
<TableRow key={index}>
{table.getVisibleLeafColumns().map((column) => (
<TableCell key={column.id}>

View File

@@ -220,13 +220,14 @@ function SubscriptionDetailRouteComponent() {
</div>
</div>
{subscription.credential3rd && (
{subscription.category ===
SubscriptionCategoryEnum.MikanSeason && (
<>
<div className="space-y-2">
<Label className="font-medium text-sm">Credential ID</Label>
<div className="rounded-md bg-muted p-3">
<code className="text-sm">
{subscription.credential3rd.id}
{subscription.credential3rd?.id ?? '-'}
</code>
</div>
</div>
@@ -237,7 +238,7 @@ function SubscriptionDetailRouteComponent() {
</Label>
<div className="rounded-md bg-muted p-3">
<code className="text-sm">
{subscription.credential3rd.username}
{subscription.credential3rd?.username ?? '-'}
</code>
</div>
</div>

View File

@@ -90,6 +90,7 @@ function SubscriptionManageRouteComponent() {
},
}
);
const [updateSubscription] = useMutation(UPDATE_SUBSCRIPTIONS, {
onCompleted: async () => {
const refetchResult = await refetch();
@@ -260,7 +261,7 @@ function SubscriptionManageRouteComponent() {
}, [handleUpdateRecord, handleDeleteRecord, navigate]);
const table = useReactTable({
data: data?.subscriptions?.nodes ?? [],
data: useMemo(() => subscriptions?.nodes ?? [], [subscriptions]),
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
@@ -270,6 +271,8 @@ function SubscriptionManageRouteComponent() {
pageCount: subscriptions?.paginationInfo?.pages,
rowCount: subscriptions?.paginationInfo?.total,
enableColumnPinning: true,
autoResetPageIndex: true,
manualPagination: true,
state: {
pagination,
sorting,
@@ -323,7 +326,7 @@ function SubscriptionManageRouteComponent() {
</TableHeader>
<TableBody>
{showSkeleton &&
Array.from(new Array(pagination.pageSize)).map((_, index) => (
Array.from(new Array(10)).map((_, index) => (
<TableRow key={index}>
{table.getVisibleLeafColumns().map((column) => (
<TableCell key={column.id}>