spacedrive/interface/app/route-schemas.ts
Brendan Allan ae31e10e0b
[ENG-1436] Store search state in search params (#1795)
* source search query from search params

* store filters in search params with round trip

* the rest bc apparently i forgot some?

* remove all references to overview

* add /:libraryId redirect
2023-11-17 21:07:33 +00:00

43 lines
1.7 KiB
TypeScript

import { z } from '@sd/ui/src/forms';
export const SortOrderSchema = z.union([z.literal('Asc'), z.literal('Desc')]);
export type SortOrder = z.infer<typeof SortOrderSchema>;
export const NodeIdParamsSchema = z.object({ id: z.string() });
export type NodeIdParams = z.infer<typeof NodeIdParamsSchema>;
export const LibraryIdParamsSchema = z.object({ libraryId: z.string().optional() });
export type LibraryIdParams = z.infer<typeof LibraryIdParamsSchema>;
export const LocationIdParamsSchema = z.object({ id: z.coerce.number() });
export type LocationIdParams = z.infer<typeof LocationIdParamsSchema>;
export const TagsSettingsParamsSchema = LocationIdParamsSchema.extend({
id: LocationIdParamsSchema.shape.id.optional()
});
export type TagsSettingsParams = z.infer<typeof TagsSettingsParamsSchema>;
export const PathParamsSchema = z.object({ path: z.string().optional() });
export type PathParams = z.infer<typeof PathParamsSchema>;
export const SearchIdParamsSchema = z.object({ id: z.coerce.number() });
export type SearchIdParams = z.infer<typeof SearchIdParamsSchema>;
export const SearchParamsSchema = PathParamsSchema.extend({
// take: z.coerce.number().default(100),
// order: z
// .union([
// z.object({ field: z.literal('name'), value: SortOrderSchema }),
// z.object({ field: z.literal('dateCreated'), value: SortOrderSchema })
// // z.object({ field: z.literal('sizeInBytes'), value: SortOrderSchema })
// ])
// .optional(),
search: z.string().optional()
});
export type SearchParams = z.infer<typeof SearchParamsSchema>;
export const ExplorerParamsSchema = PathParamsSchema.extend({
take: z.coerce.number().default(100)
});
export type ExplorerParams = z.infer<typeof ExplorerParamsSchema>;