mirror of https://github.com/Nezreka/SoulSync.git
- add a shared shell client and root /status query - attach shell status to the TanStack root context for React routes - keep the shell bridge types and test setup aligned with the new status datapull/590/head
parent
ca84aa2e65
commit
fec66e4de8
@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { HttpResponse, http, server } from '@/test/msw';
|
||||
|
||||
import { fetchShellStatus } from './status';
|
||||
|
||||
describe('shell status', () => {
|
||||
it('fetches the shell status payload', async () => {
|
||||
server.use(
|
||||
http.get('/status', () =>
|
||||
HttpResponse.json({ media_server: { type: 'plex', connected: true } }),
|
||||
),
|
||||
);
|
||||
|
||||
await expect(fetchShellStatus()).resolves.toEqual({
|
||||
media_server: { type: 'plex', connected: true },
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,25 @@
|
||||
import { queryOptions } from '@tanstack/react-query';
|
||||
|
||||
import { readJson, shellClient } from '@/app/api-client';
|
||||
|
||||
export interface ShellStatusMediaServer {
|
||||
type?: string | null;
|
||||
connected?: boolean | null;
|
||||
}
|
||||
|
||||
export interface ShellStatusPayload {
|
||||
media_server?: ShellStatusMediaServer | null;
|
||||
}
|
||||
|
||||
export async function fetchShellStatus(): Promise<ShellStatusPayload> {
|
||||
return await readJson<ShellStatusPayload>(shellClient.get('status'));
|
||||
}
|
||||
|
||||
export function shellStatusQueryOptions() {
|
||||
return queryOptions({
|
||||
queryKey: ['shell', 'status'] as const,
|
||||
queryFn: fetchShellStatus,
|
||||
staleTime: 30_000,
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue