Feat/notes init (#40)

* feat: notes init

* Feat/notes page (#39)

* wip: notes page ui added

* notes page basic ui done

* wip: page UI

* minor cleanup

* todo comments added for easy ref for backend wiring

---------

Co-authored-by: amadeus-x1 <45001978+amadeus-x1@users.noreply.github.com>

* feat: wire up notes

---------

Co-authored-by: amadeus-x1 <45001978+amadeus-x1@users.noreply.github.com>
This commit is contained in:
Haritabh 2025-09-10 16:13:33 +05:30 committed by GitHub
parent 674092f1b7
commit a128ec7972
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 2980 additions and 10 deletions

View file

@ -6,6 +6,7 @@ import { settingsRouter } from "./routers/settings";
import { updaterRouter } from "./routers/updater";
import { recordingRouter } from "./routers/recording";
import { widgetRouter } from "./routers/widget";
import { notesRouter } from "./routers/notes";
import { createRouter, procedure } from "./trpc";
export const router = createRouter({
@ -53,6 +54,9 @@ export const router = createRouter({
// Widget router
widget: widgetRouter,
// Notes router
notes: notesRouter,
});
export type AppRouter = typeof router;

View file

@ -0,0 +1,104 @@
import { z } from "zod";
import { createRouter, procedure } from "../trpc";
import NotesService from "../../services/notes-service";
const notesService = NotesService.getInstance();
// Input schemas
const GetNotesSchema = z.object({
limit: z.number().optional().default(50),
offset: z.number().optional().default(0),
sortBy: z
.enum(["title", "updatedAt", "createdAt"])
.optional()
.default("updatedAt"),
sortOrder: z.enum(["asc", "desc"]).optional().default("desc"),
search: z.string().optional(),
transcriptionId: z.number().nullable().optional(),
});
const CreateNoteSchema = z.object({
title: z.string().min(1),
initialContent: z.string().optional(),
icon: z.string().nullish(),
});
const UpdateNoteTitleSchema = z.object({
id: z.number(),
title: z.string().min(1),
});
const UpdateNoteIconSchema = z.object({
id: z.number(),
icon: z.string().nullish(),
});
export const notesRouter = createRouter({
// Get all notes
getNotes: procedure.input(GetNotesSchema).query(async ({ input }) => {
return await notesService.listNotes({
limit: input.limit,
offset: input.offset,
sortBy: input.sortBy,
sortOrder: input.sortOrder,
search: input.search,
transcriptionId: input.transcriptionId,
});
}),
// Get note by ID
getNoteById: procedure
.input(z.object({ id: z.number() }))
.query(async ({ input }) => {
const note = await notesService.getNote(input.id);
if (!note) {
throw new Error("Note not found");
}
return note;
}),
// Create new note
createNote: procedure.input(CreateNoteSchema).mutation(async ({ input }) => {
return await notesService.createNote({
title: input.title,
initialContent: input.initialContent || "",
icon: input.icon,
});
}),
// Update note title
updateNoteTitle: procedure
.input(UpdateNoteTitleSchema)
.mutation(async ({ input }) => {
const updated = await notesService.updateNote(input.id, {
title: input.title,
});
if (!updated) {
throw new Error("Failed to update note");
}
return updated;
}),
updateNoteIcon: procedure
.input(UpdateNoteIconSchema)
.mutation(async ({ input }) => {
const updated = await notesService.updateNote(input.id, {
icon: input.icon,
});
if (!updated) {
throw new Error("Failed to update note");
}
return updated;
}),
// Delete note
deleteNote: procedure
.input(z.object({ id: z.number() }))
.mutation(async ({ input }) => {
const deleted = await notesService.deleteNote(input.id);
if (!deleted) {
throw new Error("Note not found");
}
return { success: true };
}),
});