diff --git a/.husky/pre-commit b/.husky/pre-commit index 8033d4c..603c844 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,3 +1,2 @@ pnpm pre-commit -pnpm typecheck git add . diff --git a/lint-staged.config.js b/lint-staged.config.js index 4c31120..722b709 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,4 +1,4 @@ /** @type {import('./lib/types').Configuration} */ export default { - '*': ['pnpm format', 'pnpm lint', 'tsc-files --noEmit'] + '*': ['pnpm format', 'pnpm lint', 'tsc-files --noEmit -p tsconfig.json --composite false'] } diff --git a/src/renderer/src/components/home/components/note-list.tsx b/src/renderer/src/components/home/components/note-list.tsx index 718fc5e..acdd068 100644 --- a/src/renderer/src/components/home/components/note-list.tsx +++ b/src/renderer/src/components/home/components/note-list.tsx @@ -13,7 +13,7 @@ export function NoteList({ items }: NoteListProps): React.JSX.Element { const { pathname } = useLocation() const noteId = pathname.replace('/', '') return ( - +
{items.map((item) => ( @@ -52,6 +52,8 @@ export function NoteList({ items }: NoteListProps): React.JSX.Element { ))}
+ {/* TODO - make this component animate that automatically decrease its height to h-8 when it is on view this will create a stretchy effect on list */} +
) } diff --git a/src/renderer/src/components/home/index.tsx b/src/renderer/src/components/home/index.tsx index 903232f..22f7833 100644 --- a/src/renderer/src/components/home/index.tsx +++ b/src/renderer/src/components/home/index.tsx @@ -3,7 +3,15 @@ import { Separator } from '../ui/separator' import { TooltipProvider } from '../ui/tooltip' import { NoteInterface } from '@renderer/types/notes' import { NoteList } from './components/note-list' -import { Outlet } from '@tanstack/react-router' +import { Outlet, useNavigate } from '@tanstack/react-router' +import { Button } from '../ui/button' +import { PlusIcon } from 'lucide-react' +import { SimpleTooltip } from '../shared/simple-tooltip' +import { useMutation, useQueryClient } from '@tanstack/react-query' +import { allNoteKey } from '@renderer/constants/query-keys' +import { mutationKeys } from '@renderer/constants/mutation-keys' +import { toast } from '@renderer/hooks/use-toast' +import { noteTitleDescription } from '@renderer/utils' interface NoteProps { readonly Notes: NoteInterface[] @@ -11,7 +19,38 @@ interface NoteProps { readonly defaultCollapsed?: boolean } +interface FormValues { + title: string + description: string +} +const defaultNoteValues = { title: 'Untitled', description: 'no description available' } export function Note({ Notes, defaultLayout = [12, 32, 48] }: NoteProps): React.JSX.Element { + const queryClient = useQueryClient() + const navigate = useNavigate() + const { mutate } = useMutation({ + mutationKey: [mutationKeys['create-note']], + mutationFn: (values: FormValues & { content: object | unknown[] }) => + window.api.createNote(values), + async onSettled(data) { + await queryClient.cancelQueries({ queryKey: allNoteKey }) + if (!data) throw Error('Returned Data is Empty') + queryClient.setQueryData(allNoteKey, (previousEntities) => { + // Ensure previousEntities is an array, defaulting to an empty array if it's undefined + const entities = previousEntities || [] + const createdNote = data || {} + return [...entities, createdNote] + }) + toast({ title: 'New Note Created 🎉' }) + navigate({ to: `/${data.id}` }) + }, + onError(error) { + toast({ + title: 'Failed to create note ❌ ', + description: error.message, + variant: 'destructive' + }) + } + }) return ( -
+

All Notes

+ + +
-
+
diff --git a/src/renderer/src/components/modals/create-note-modal.tsx b/src/renderer/src/components/modals/create-note-modal.tsx index caafc2a..69b0cc6 100644 --- a/src/renderer/src/components/modals/create-note-modal.tsx +++ b/src/renderer/src/components/modals/create-note-modal.tsx @@ -32,7 +32,14 @@ interface FormValues { title: string description: string } - +/** + * TODO - remove this component once the create note method is improved in production + * @deprecated Create note modal is now deprecated for better UI we are going to do something like + * - user click on create new note + * - then a new Note will Immediately created with default configs like + * - title --- untitled note + * - description --- (empty) + */ export function CreateNoteModal(): React.JSX.Element { const queryClient = useQueryClient() const form = useForm() @@ -74,10 +81,8 @@ export function CreateNoteModal(): React.JSX.Element { Create new Note 📒 - Begin creating a brand new one. -
@@ -87,36 +92,28 @@ export function CreateNoteModal(): React.JSX.Element { render={({ field }) => ( Username - - Title for the note. - )} /> - ( Description -