diff --git a/src/Components/Api/Api.tsx b/src/Components/Api/Api.tsx
index 000b057..84bd8b3 100644
--- a/src/Components/Api/Api.tsx
+++ b/src/Components/Api/Api.tsx
@@ -1,6 +1,7 @@
import axios from "axios";
import {
ActivationParams,
+ UpdateNoteParams,
AddNoteParams,
LoginParams,
RegistrationParams,
@@ -21,6 +22,36 @@ export function GetNotes() {
});
}
+export function GetNote(id: number) {
+ const token = JSON.parse(localStorage.getItem("token") || "");
+ return axios
+ .get("http://localhost:8000/api/v1/notes/" + id + "/", {
+ headers: {
+ Authorization: "Token " + token,
+ },
+ })
+ .then((response) => {
+ return response.data;
+ });
+}
+
+export function UpdateNote(note: UpdateNoteParams) {
+ const token = JSON.parse(localStorage.getItem("token") || "");
+ return axios
+ .patch("http://localhost:8000/api/v1/notes/" + note.id + "/", note, {
+ headers: {
+ Authorization: "Token " + token,
+ },
+ })
+ .then((response) => {
+ return response.data;
+ })
+ .catch((error) => {
+ console.log("Error updating note", error);
+ return error;
+ });
+}
+
export function AddNote(note: AddNoteParams) {
const token = JSON.parse(localStorage.getItem("token") || "");
return axios
diff --git a/src/Components/Note/Note.tsx b/src/Components/Note/Note.tsx
index 39685da..59003e7 100644
--- a/src/Components/Note/Note.tsx
+++ b/src/Components/Note/Note.tsx
@@ -4,8 +4,10 @@ import { Button } from "@mui/material";
import { useMutation, useQueryClient } from "react-query";
import { DeleteNote } from "../Api/Api";
import { NoteProps } from "../../Interfaces/Interfaces";
+import { useNavigate } from "react-router-dom";
export default function Note(props: NoteProps) {
+ const navigate = useNavigate();
const queryClient = useQueryClient();
const mutation = useMutation({
mutationFn: DeleteNote,
@@ -28,15 +30,26 @@ export default function Note(props: NoteProps) {
Timestamp: {String(props.date_created)}
-
+
+
+
+
);
diff --git a/src/Interfaces/Interfaces.tsx b/src/Interfaces/Interfaces.tsx
index 58219e8..afd5f25 100644
--- a/src/Interfaces/Interfaces.tsx
+++ b/src/Interfaces/Interfaces.tsx
@@ -50,3 +50,9 @@ export interface AddNoteParams {
title: string;
content: string;
}
+
+export interface UpdateNoteParams {
+ id: number;
+ title: string;
+ content: string;
+}
diff --git a/src/Routes/ViewEditNote/ViewEditNote.tsx b/src/Routes/ViewEditNote/ViewEditNote.tsx
new file mode 100644
index 0000000..62b5009
--- /dev/null
+++ b/src/Routes/ViewEditNote/ViewEditNote.tsx
@@ -0,0 +1,115 @@
+import styles from "../../styles";
+import { Button } from "@mui/material";
+import { useNavigate, useParams } from "react-router-dom";
+import { useEffect, useState } from "react";
+import Header from "../../Components/Header/Header";
+import { AddNote, GetNote, UpdateNote } from "../../Components/Api/Api";
+import { useMutation, useQuery, useQueryClient } from "react-query";
+import { NoteProps } from "../../Interfaces/Interfaces";
+
+export interface input {
+ e: React.ChangeEvent;
+}
+export default function ViewNote() {
+ const navigate = useNavigate();
+ const { id } = useParams();
+ const queryClient = useQueryClient();
+ const mutation = useMutation({
+ mutationFn: UpdateNote,
+ onSuccess: () => {
+ queryClient.invalidateQueries("notes");
+ },
+ });
+ const [note, setNote] = useState({
+ title: "test",
+ content: "test",
+ });
+ async function retrieve() {
+ let a = await GetNote(Number(id));
+ setNote(a);
+ return a;
+ }
+ const { data, isLoading, error } = useQuery("note", retrieve, {
+ retry: 0,
+ });
+ useEffect(() => {
+ setNote(data);
+ }, []);
+ if (error) {
+ return (
+
+
+
+
Error retrieving specific note
+
+
+ );
+ }
+ if (isLoading) {
+ return (
+
+ );
+ }
+ if (data) {
+ return (
+
+
+
Edit Note
+
+
+
+
Title:
+
{
+ setNote({ ...note, title: e.target.value });
+ }}
+ maxLength={20}
+ />
+
+
+
+
+
+
+
+
+
+
+ );
+ }
+ return heh
;
+}
diff --git a/src/index.tsx b/src/index.tsx
index 2adba04..0407eef 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -14,6 +14,7 @@ import { QueryClient, QueryClientProvider } from "react-query";
import { Provider } from "react-redux";
import Store from "./Features/Redux/Store/Store";
+import ViewEditNote from "./Routes/ViewEditNote/ViewEditNote";
const queryClient = new QueryClient();
@@ -38,6 +39,10 @@ const router = createBrowserRouter([
path: "/Activation/:uid/:token",
element: ,
},
+ {
+ path: "/Note/:id",
+ element: ,
+ },
]);
const root = ReactDOM.createRoot(
diff --git a/src/styles.tsx b/src/styles.tsx
index ab9d01f..b24c487 100644
--- a/src/styles.tsx
+++ b/src/styles.tsx
@@ -81,7 +81,8 @@ const styles: { [key: string]: React.CSSProperties } = {
height: "100%",
width: "100%",
minWidth: "100%",
- minHeight: "512px",
+ minHeight: "256px",
+ maxHeight: "768px",
fontSize: "2vh",
fontWeight: "bold",
},
@@ -91,8 +92,7 @@ const styles: { [key: string]: React.CSSProperties } = {
display: "flex",
flexDirection: "row",
width: "256x",
- marginTop: 4,
- marginBottom: 4,
+ margin: 4,
},
button_yellow: {
backgroundColor: "#e2b465",
@@ -100,8 +100,7 @@ const styles: { [key: string]: React.CSSProperties } = {
display: "flex",
flexDirection: "row",
width: "256px",
- marginTop: 4,
- marginBottom: 4,
+ margin: 4,
},
button_red: {
backgroundColor: "#bc231e",
@@ -109,8 +108,7 @@ const styles: { [key: string]: React.CSSProperties } = {
display: "flex",
flexDirection: "row",
width: "256px",
- marginTop: 4,
- marginBottom: 4,
+ margin: 4,
},
text_small: {
color: "white",