Skip to content

Commit

Permalink
Added the 'Note' type to get rid of some of the annoying errors
Browse files Browse the repository at this point in the history
	modified:   src-tauri/tauri.conf.json
	modified:   src/App.tsx
	modified:   src/components/NoteEditor.tsx
	modified:   src/components/NotesSidebar.tsx
	modified:   src/store/notesStore.ts
	new file:   src/types/Note.ts
  • Loading branch information
mumamomumo committed Dec 20, 2024
1 parent 6044239 commit e26da60
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "given-up",
"productName": "Note Taking App",
"version": "0.1.0",
"identifier": "com.tauri.dev",
"identifier": "notes.taker",
"build": {
"frontendDist": "../build",
"frontendDist": "../dist",
"devUrl": "http://localhost:5173",
"beforeDevCommand": "cross-env BROWSER=none npm run start",
"beforeBuildCommand": "npm run build"
Expand Down
7 changes: 4 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import {
} from "./components/ui/resizable";

import { loadNotes } from "./data/notesStorage";
import { Note } from "./types/Note";

export default function App() {
const [openNote, setOpenNote] = useState(null);
const [openNote, setOpenNote] = useState<Note | null>(null);
const notes = useNotesStore((state) => state.notes);
const addNote = useNotesStore((state) => state.addNote);
const updateNote = useNotesStore((state) => state.updateNote);
Expand Down Expand Up @@ -50,8 +51,8 @@ export default function App() {
<ResizablePanel minSize={40}>
{openNote ? (
<NoteEditor
title={openNote?.title}
content={openNote?.content}
title={openNote.title}
content={openNote.content}
id={openNote.id}
updateNote={updateNote}
/>
Expand Down
10 changes: 5 additions & 5 deletions src/components/NoteEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ function NoteEditor(props: {
id: number;
updateNote: Function;
}): JSX.Element {
const titleRef = useRef(null);
const contentRef = useRef(null);
const titleRef = useRef<HTMLInputElement>(null);
const contentRef = useRef<HTMLTextAreaElement>(null);

const updateNote = () => {
props.updateNote(props.id, titleRef.current.value, contentRef.current.value);
props.updateNote(props.id, titleRef.current!.value, contentRef.current!.value);
};



useEffect(() => {
console.log("Note Editor change");
titleRef.current.value = props.title;
contentRef.current.value = props.content;
titleRef.current!.value = props.title;
contentRef.current!.value = props.content;
return () => {
console.log("Note Editor remove");
};
Expand Down
3 changes: 2 additions & 1 deletion src/components/NotesSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Note } from "@/types/Note";
import { Trash2, FilePlus2 } from "lucide-react";

function NotesSidebar(props: {
Expand Down Expand Up @@ -41,7 +42,7 @@ function NotesSidebar(props: {
</div>
{/* Notes List */}
<div className="notes-list">
{notes.map((note) => (
{notes.map((note: Note) => (
<div
className="note-side"
onClick={() => setOpenNote(note)}
Expand Down
3 changes: 2 additions & 1 deletion src/store/notesStore.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { create } from "zustand";
import { saveNotes } from "@/data/notesStorage";
import { Note } from "@/types/Note";

export type NotesStore = {
notes: Array<{ id: number; title: string; content: string }>;
notes: Array<Note>;
addNote: (title: string, content: string) => void;
removeNote: (id: number) => void;
updateNote: (id: number, title: string, content: string) => void;
Expand Down
5 changes: 5 additions & 0 deletions src/types/Note.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface Note {
id: any;
title: string;
content: string;
}

0 comments on commit e26da60

Please sign in to comment.