diff --git a/src/Features/Redux/Store/Api.tsx b/src/Features/Redux/Store/Api.tsx deleted file mode 100644 index d93144c..0000000 --- a/src/Features/Redux/Store/Api.tsx +++ /dev/null @@ -1,134 +0,0 @@ -import axios from "axios"; -import { - ActivationParams, - UpdateNoteParams, - AddNoteParams, - LoginParams, - RegistrationParams, -} from "../../Interfaces/Interfaces"; - -// Note APIs - -const instance = axios.create({ - baseURL: "https://keannu126.pythonanywhere.com", -}); - -export function GetNotes() { - const token = JSON.parse(localStorage.getItem("token") || "{}"); - return instance - .get("/api/v1/notes/", { - headers: { - Authorization: "Token " + token, - }, - }) - .then((response) => { - return response.data; - }); -} - -export function GetNote(id: number) { - const token = JSON.parse(localStorage.getItem("token") || "{}"); - return instance - .get("/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 instance - .patch("/api/v1/notes/" + note.id + "/", note, { - headers: { - Authorization: "Token " + token, - }, - }) - .then((response) => { - return response.data; - }) - .catch((error) => { - return error; - }); -} - -export function AddNote(note: AddNoteParams) { - const token = JSON.parse(localStorage.getItem("token") || "{}"); - return instance - .post("/api/v1/notes/", note, { - headers: { - Authorization: "Token " + token, - }, - }) - .then((response) => { - return response.data; - }) - .catch((error) => { - return error; - }); -} - -export function DeleteNote(id: number) { - const token = JSON.parse(localStorage.getItem("token") || "{}"); - return instance - .delete("/api/v1/notes/" + id + "/", { - headers: { - Authorization: "Token " + token, - }, - }) - .catch((error) => { - return error; - }); -} - -// User APIs - -export function UserRegister(register: RegistrationParams) { - return instance - .post("/api/v1/accounts/users/", register) - .then(async (response) => { - return true; - }) - .catch((error) => { - return false; - }); -} - -export function UserLogin(user: LoginParams) { - return instance - .post("/api/v1/accounts/token/login/", user) - .then(async (response) => { - localStorage.setItem("token", JSON.stringify(response.data.auth_token)); - return true; - }) - .catch((error) => { - return false; - }); -} - -export function UserInfo() { - const token = JSON.parse(localStorage.getItem("token") || "{}"); - return instance - .get("/api/v1/accounts/users/me/", { - headers: { - Authorization: "Token " + token, - }, - }) - .then((response) => { - return response.data; - }); -} - -export function UserActivate(activation: ActivationParams) { - return instance - .post("/api/v1/accounts/users/activation/", activation) - .then(async (response) => { - return true; - }) - .catch((error) => { - return false; - }); -} diff --git a/src/Features/Redux/Store/ViewEditNote.tsx b/src/Features/Redux/Store/ViewEditNote.tsx deleted file mode 100644 index 3226e69..0000000 --- a/src/Features/Redux/Store/ViewEditNote.tsx +++ /dev/null @@ -1,116 +0,0 @@ -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 { GetNote, UpdateNote } from "../../Components/Api/Api"; -import { useMutation, useQuery, useQueryClient } from "react-query"; - -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: "", - content: "", - }); - 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); - }, [data]); - if (error) { - return ( -
-
-
-

Error retrieving specific note

-
-
- ); - } - if (isLoading) { - return ( -
-
-

Loading Note...

-
-
- ); - } - if (data) { - return ( -
-
-

Edit Note

-
-
-
-

Title: 

- { - setNote({ ...note, title: e.target.value }); - }} - maxLength={20} - /> -
-
-