diff --git a/src/api/note/index.ts b/src/api/note/index.ts index 9ecf459..16bf7a1 100644 --- a/src/api/note/index.ts +++ b/src/api/note/index.ts @@ -1,7 +1,14 @@ import ms from "ms"; import { type ServiceArgs, createQueryService, createService } from "../helpers/createService"; import { jsonFetch } from "../helpers/jsonFetch"; -import type { CreateNote, Note, NoteParams, NoteSearchParams, Notes } from "./schema"; +import type { + CreateNote, + FavouriteNote, + Note, + NoteParams, + NoteSearchParams, + Notes, +} from "./schema"; export const notesService = { getAll: createQueryService({ @@ -36,4 +43,9 @@ export const notesService = { body: JSON.stringify(args.body), }), }), + favourite: createService({ + url: "/notes/:noteId/favourite", + call: (url, args: ServiceArgs<{ urlParams: NoteParams; body: FavouriteNote }>) => + jsonFetch({ ...args, url, method: "POST", body: JSON.stringify(args.body) }), + }), }; diff --git a/src/api/note/mocks.ts b/src/api/note/mocks.ts index 0ddcc3a..b2f9971 100644 --- a/src/api/note/mocks.ts +++ b/src/api/note/mocks.ts @@ -9,5 +9,6 @@ export const createNoteMock = (opts?: PartialDeep): Note => ({ id: randUuid(), title: randWord({ length: 5 }).join(" "), content: randSentence(), + isFavourite: false, ...opts, }); diff --git a/src/api/note/schema.ts b/src/api/note/schema.ts index 4ec6390..53c9047 100644 --- a/src/api/note/schema.ts +++ b/src/api/note/schema.ts @@ -8,6 +8,7 @@ export const NoteSchema = z.object({ id: z.string().uuid(), title: z.string(), content: z.string(), + isFavourite: z.boolean().default(false).optional(), }); export type Note = z.infer; @@ -17,4 +18,9 @@ export type Notes = z.infer; export const CreateNoteSchema = NoteSchema.pick({ title: true, content: true }); export type CreateNote = z.infer; -export type NoteSearchParams = { search: string }; +export type NoteSearchParams = { search: string; favouritesOnly?: "true" | "false" }; + +export const FavouriteNoteSchema = z.object({ + isFavourite: z.boolean(), +}); +export type FavouriteNote = z.infer; diff --git a/src/components/Form.tsx b/src/components/Form.tsx index 4be76e2..ede0567 100644 --- a/src/components/Form.tsx +++ b/src/components/Form.tsx @@ -1,3 +1,4 @@ +import clsx from "clsx"; import type { ComponentPropsWithoutRef } from "react"; export const Label = ({ children, ...props }: ComponentPropsWithoutRef<"label">) => ( @@ -9,13 +10,19 @@ export const Label = ({ children, ...props }: ComponentPropsWithoutRef<"label">) export const Input = (props: ComponentPropsWithoutRef<"input">) => ( ); export const Textarea = (props: ComponentPropsWithoutRef<"textarea">) => (