diff --git a/src/Components/Api/Api.tsx b/src/Components/Api/Api.tsx
index e2aa672..e5ec623 100644
--- a/src/Components/Api/Api.tsx
+++ b/src/Components/Api/Api.tsx
@@ -26,6 +26,19 @@ export function GetNotes() {
});
}
+export function GetPublicNotes() {
+ const token = JSON.parse(localStorage.getItem("token") || "{}");
+ return instance
+ .get("/api/v1/public_notes/", {
+ headers: {
+ Authorization: "Token " + token,
+ },
+ })
+ .then((response) => {
+ return response.data;
+ });
+}
+
export function GetNote(id: number) {
const token = JSON.parse(localStorage.getItem("token") || "{}");
return instance
diff --git a/src/Components/PublicNote/Note.tsx b/src/Components/PublicNote/Note.tsx
new file mode 100644
index 0000000..a1454c9
--- /dev/null
+++ b/src/Components/PublicNote/Note.tsx
@@ -0,0 +1,25 @@
+import * as React from "react";
+import styles from "../../styles";
+import { NoteProps } from "../../Interfaces/Interfaces";
+
+export default function PublicNote(props: NoteProps) {
+ return (
+
+
+
Owner: {props.owner}
+
Title: {props.title}
+
+
+
+
+ Timestamp: {String(props.date_created)}
+
+
Public: {props.public ? "Yes" : "No"}
+
+
+ );
+}
diff --git a/src/Components/PublicNotes/Notes.tsx b/src/Components/PublicNotes/Notes.tsx
new file mode 100644
index 0000000..6889c29
--- /dev/null
+++ b/src/Components/PublicNotes/Notes.tsx
@@ -0,0 +1,66 @@
+import * as React from "react";
+import styles from "../../styles";
+import { useNavigate } from "react-router-dom";
+import Note from "../Note/Note";
+import { Button } from "@mui/material";
+import { useQuery } from "react-query";
+import { GetPublicNotes } from "../Api/Api";
+import { useSelector } from "react-redux";
+import { NoteProps } from "../../Interfaces/Interfaces";
+import { RootState } from "../../Features/Redux/Store/Store";
+import PublicNote from "../PublicNote/Note";
+
+export default function PublicNotes() {
+ const navigate = useNavigate();
+ const {
+ data: notes,
+ isLoading,
+ error,
+ } = useQuery("public_notes", GetPublicNotes, { retry: 0 });
+ if (isLoading) {
+ return (
+
+ );
+ } else if (error) {
+ return (
+
+
Error contacting Notes server
+
+ );
+ } else if (notes.length === 0) {
+ return (
+
+
No notes exist yet
+
Make one!
+
+
+ );
+ }
+ return (
+ <>
+ {notes.map((note: NoteProps, index: number) => {
+ return (
+
+ );
+ })}
+ >
+ );
+}
diff --git a/src/Components/ViewToggle/ViewToggle.tsx b/src/Components/ViewToggle/ViewToggle.tsx
new file mode 100644
index 0000000..ced5423
--- /dev/null
+++ b/src/Components/ViewToggle/ViewToggle.tsx
@@ -0,0 +1,65 @@
+import * as React from "react";
+import { useState } from "react";
+import styles from "../../styles";
+import { Switch } from "@mui/material";
+import Notes from "../Notes/Notes";
+import PublicNotes from "../PublicNotes/Notes";
+
+export default function ViewToggle() {
+ const [switchLabel, setLabel] = useState("Viewing public notes");
+ const [togglePublic, setToggled] = useState(true);
+ if (togglePublic) {
+ return (
+
+
+
{
+ setToggled(!togglePublic);
+ if (togglePublic) {
+ setLabel("Viewing own notes");
+ } else {
+ setLabel("Viewing public notes");
+ }
+ }}
+ />
+ {switchLabel}
+
+
+
+ );
+ }
+ return (
+
+
+
{
+ setToggled(!togglePublic);
+ if (togglePublic) {
+ setLabel("Viewing own notes");
+ } else {
+ setLabel("Viewing public notes");
+ }
+ }}
+ />
+ {switchLabel}
+
+
+
+ );
+}
diff --git a/src/Routes/Home/Home.tsx b/src/Routes/Home/Home.tsx
index ddc9770..e069b13 100644
--- a/src/Routes/Home/Home.tsx
+++ b/src/Routes/Home/Home.tsx
@@ -1,11 +1,11 @@
import styles from "../../styles";
import Header from "../../Components/Header/Header";
-import Notes from "../../Components/Notes/Notes";
+import ViewToggle from "../../Components/ViewToggle/ViewToggle";
export default function Home() {
return (
-
+
);
}