Merge pull request #9 from lemeow125/feature/notes_per_user

Feature/notes per user
This commit is contained in:
lemeow125 2023-03-05 20:39:48 +08:00 committed by GitHub
commit 9ccb8624af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 455 additions and 156 deletions

View file

@ -1,38 +1,91 @@
import axios from "axios"; import axios from "axios";
import {
ActivationParams,
UpdateNoteParams,
AddNoteParams,
LoginParams,
RegistrationParams,
} from "../../Interfaces/Interfaces";
// Note APIs // Note APIs
export function GetNotes() { export function GetNotes() {
return axios.get("http://localhost:8000/api/v1/notes/").then((response) => { const token = JSON.parse(localStorage.getItem("token") || "{}");
return response.data;
});
}
export interface note {
title: string;
content: string;
}
export function AddNote(note: note) {
return axios return axios
.post("http://localhost:8000/api/v1/notes/", note) .get("http://localhost:8000/api/v1/notes/", {
headers: {
Authorization: "Token " + token,
},
})
.then((response) => { .then((response) => {
return response.data; return response.data;
}); });
} }
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
.post("http://localhost:8000/api/v1/notes/", note, {
headers: {
Authorization: "Token " + token,
},
})
.then((response) => {
return response.data;
})
.catch((error) => {
console.log("Error adding note", error);
return error;
});
}
export function DeleteNote(id: number) { export function DeleteNote(id: number) {
return axios.delete("http://localhost:8000/api/v1/notes/" + id + "/"); const token = JSON.parse(localStorage.getItem("token") || "{}");
return axios
.delete("http://localhost:8000/api/v1/notes/" + id + "/", {
headers: {
Authorization: "Token " + token,
},
})
.catch((error) => {
console.log("Error deleting note", error);
return error;
});
} }
// User APIs // User APIs
export interface register {
email: string;
username: string;
password: string;
}
export function UserRegister(register: register) { export function UserRegister(register: RegistrationParams) {
return axios return axios
.post("http://localhost:8000/api/v1/accounts/users/", register) .post("http://localhost:8000/api/v1/accounts/users/", register)
.then(async (response) => { .then(async (response) => {
@ -45,19 +98,14 @@ export function UserRegister(register: register) {
}); });
} }
export interface user { export function UserLogin(user: LoginParams) {
username: string;
password: string;
}
export function UserLogin(user: user) {
return axios return axios
.post("http://localhost:8000/api/v1/accounts/token/login/", user) .post("http://localhost:8000/api/v1/accounts/token/login/", user)
.then(async (response) => { .then(async (response) => {
localStorage.setItem("token", JSON.stringify(response.data.auth_token)); localStorage.setItem("token", JSON.stringify(response.data.auth_token));
console.log( console.log(
"Login Success! Stored Token: ", "Login Success! Stored Token: ",
JSON.parse(localStorage.getItem("token") || "") JSON.parse(localStorage.getItem("token") || "{}")
); );
return true; return true;
}) })
@ -68,7 +116,7 @@ export function UserLogin(user: user) {
} }
export function UserInfo() { export function UserInfo() {
const token = JSON.parse(localStorage.getItem("token") || ""); const token = JSON.parse(localStorage.getItem("token") || "{}");
return axios return axios
.get("http://localhost:8000/api/v1/accounts/users/me/", { .get("http://localhost:8000/api/v1/accounts/users/me/", {
headers: { headers: {
@ -76,20 +124,12 @@ export function UserInfo() {
}, },
}) })
.then((response) => { .then((response) => {
console.log(response.data);
return response.data; return response.data;
})
.catch((error) => {
console.log("Error in fetching user data");
console.log(error);
}); });
} }
export interface activation { export function UserActivate(activation: ActivationParams) {
uid: string;
token: string;
}
export function UserActivate(activation: activation) {
return axios return axios
.post("http://localhost:8000/api/v1/accounts/users/activation/", activation) .post("http://localhost:8000/api/v1/accounts/users/activation/", activation)
.then(async (response) => { .then(async (response) => {

View file

@ -1,11 +1,7 @@
import * as React from "react"; import * as React from "react";
import { IconProps } from "../../Interfaces/Interfaces";
export interface props { export default function AppIcon(props: IconProps) {
size: number;
color: string;
}
export default function AppIcon(props: props) {
return ( return (
<> <>
<svg <svg
@ -13,11 +9,11 @@ export default function AppIcon(props: props) {
width={props.size + "px"} width={props.size + "px"}
height={props.size + "px"} height={props.size + "px"}
viewBox="0 0 24 24" viewBox="0 0 24 24"
stroke-width="2" strokeWidth="2"
stroke={props.color} stroke={props.color}
fill="none" fill="none"
stroke-linecap="round" strokeLinecap="round"
stroke-linejoin="round" strokeLinejoin="round"
> >
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2"></path> <path d="M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2"></path>

View file

@ -4,6 +4,7 @@ import styles from "../../styles";
import AppIcon from "../AppIcon/AppIcon"; import AppIcon from "../AppIcon/AppIcon";
import Login from "../LoginButton/LoginButton"; import Login from "../LoginButton/LoginButton";
import HomeIcon from "../HomeIcon/HomeIcon"; import HomeIcon from "../HomeIcon/HomeIcon";
import UserIcon from "../UserIcon/UserIcon";
export default function Header() { export default function Header() {
return ( return (
@ -16,9 +17,7 @@ export default function Header() {
}} }}
> >
<HomeIcon size={32} color="white" /> <HomeIcon size={32} color="white" />
<HomeIcon size={32} color="white" /> <UserIcon size={32} color="white" />
<HomeIcon size={32} color="white" />
<HomeIcon size={32} color="white" />
</div> </div>
<div <div
style={{ style={{

View file

@ -1,13 +1,9 @@
import { Button } from "@mui/material"; import { Button } from "@mui/material";
import * as React from "react"; import * as React from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { IconProps } from "../../Interfaces/Interfaces";
export interface props { export default function HomeIcon(props: IconProps) {
size: number;
color: string;
}
export default function HomeIcon(props: props) {
const navigate = useNavigate(); const navigate = useNavigate();
return ( return (
<Button <Button
@ -28,11 +24,11 @@ export default function HomeIcon(props: props) {
width={props.size - 4 + "px"} width={props.size - 4 + "px"}
height={props.size - 4 + "px"} height={props.size - 4 + "px"}
viewBox="0 0 24 24" viewBox="0 0 24 24"
stroke-width="2" strokeWidth="2"
stroke={props.color} stroke={props.color}
fill="none" fill="none"
stroke-linecap="round" strokeLinecap="round"
stroke-linejoin="round" strokeLinejoin="round"
> >
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M5 12l-2 0l9 -9l9 9l-2 0"></path> <path d="M5 12l-2 0l9 -9l9 9l-2 0"></path>

View file

@ -5,23 +5,14 @@ import styles from "../../styles";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { SetLoggedOut } from "../../Features/Redux/Slices/LoginSlice/LoginSlice"; import { SetLoggedOut } from "../../Features/Redux/Slices/LoginSlice/LoginSlice";
import { UnsetUser } from "../../Features/Redux/Slices/LoggedInUserSlice/LoggedInUserSlice"; import { UnsetUser } from "../../Features/Redux/Slices/LoggedInUserSlice/LoggedInUserSlice";
import { LoggedInUserState, LoginState } from "../../Interfaces/Interfaces";
export interface user {
LoggedInUser: {
value: {
email: string;
id: number;
username: string;
};
};
}
export default function LoginButton() { export default function LoginButton() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const logged_in = useSelector( const logged_in = useSelector((state: LoginState) => state.Login.logged_in);
(state: { Login: { logged_in: boolean } }) => state.Login.logged_in const logged_in_user = useSelector(
(state: LoggedInUserState) => state.LoggedInUser.value
); );
const logged_in_user = useSelector((state: user) => state.LoggedInUser.value);
const navigate = useNavigate(); const navigate = useNavigate();
if (!logged_in) { if (!logged_in) {
return ( return (

View file

@ -3,14 +3,11 @@ import styles from "../../styles";
import { Button } from "@mui/material"; import { Button } from "@mui/material";
import { useMutation, useQueryClient } from "react-query"; import { useMutation, useQueryClient } from "react-query";
import { DeleteNote } from "../Api/Api"; import { DeleteNote } from "../Api/Api";
import { NoteProps } from "../../Interfaces/Interfaces";
import { useNavigate } from "react-router-dom";
export interface props { export default function Note(props: NoteProps) {
title: string; const navigate = useNavigate();
content: string;
id: number;
date_created: string;
}
export default function Note(props: props) {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const mutation = useMutation({ const mutation = useMutation({
mutationFn: DeleteNote, mutationFn: DeleteNote,
@ -21,20 +18,38 @@ export default function Note(props: props) {
return ( return (
<div style={styles.flex_column}> <div style={styles.flex_column}>
<div style={styles.note}> <div style={styles.note}>
<p style={styles.text_medium}>{props.title}</p> <p style={styles.text_medium}>Owner: {props.owner}</p>
<p style={styles.text_medium}>Title: {props.title}</p>
<div style={styles.note_content}> <div style={styles.note_content}>
<p style={styles.text_small}>{props.content}</p> <textarea
style={styles.input_notebody}
disabled={true}
value={props.content}
/>
</div>
<p style={styles.text_medium}>
Timestamp: {String(props.date_created)}
</p>
<div style={styles.flex_row}>
<Button
style={styles.button_red}
variant="contained"
onClick={() => {
mutation.mutate(props.id);
}}
>
Remove Note
</Button>
<Button
style={styles.button_yellow}
variant="contained"
onClick={() => {
navigate("/Note/" + props.id);
}}
>
Edit Note
</Button>
</div> </div>
<p style={styles.text_medium}>Timestamp: {props.date_created}</p>
<Button
style={styles.button_red}
variant="contained"
onClick={() => {
mutation.mutate(props.id);
}}
>
Remove Note
</Button>
</div> </div>
</div> </div>
); );

View file

@ -5,6 +5,8 @@ import Note from "../Note/Note";
import { Button } from "@mui/material"; import { Button } from "@mui/material";
import { useQuery } from "react-query"; import { useQuery } from "react-query";
import { GetNotes } from "../Api/Api"; import { GetNotes } from "../Api/Api";
import { useSelector } from "react-redux";
import { LoginState, NoteProps } from "../../Interfaces/Interfaces";
export default function Notes() { export default function Notes() {
const navigate = useNavigate(); const navigate = useNavigate();
@ -13,21 +15,26 @@ export default function Notes() {
isLoading, isLoading,
error, error,
} = useQuery("notes", GetNotes, { retry: 0 }); } = useQuery("notes", GetNotes, { retry: 0 });
if (error) { const logged_in = useSelector((state: LoginState) => state.Login.logged_in);
return (
<div style={styles.note}>
<p style={styles.text_medium_red}>Error contacting Notes server</p>
</div>
);
}
if (isLoading) { if (isLoading) {
return ( return (
<div style={styles.note}> <div style={styles.note}>
<p style={styles.text_medium}>Loading Notes...</p> <p style={styles.text_medium}>Loading Notes...</p>
</div> </div>
); );
} } else if (!logged_in && error) {
if (notes.length === 0) { return (
<div style={styles.note}>
<p style={styles.text_medium}>Please login to use Clip Notes</p>
</div>
);
} else if (error) {
return (
<div style={styles.note}>
<p style={styles.text_medium_red}>Error contacting Notes server</p>
</div>
);
} else if (notes.length === 0) {
return ( return (
<div style={styles.note}> <div style={styles.note}>
<p style={styles.text_medium}>No notes exist yet</p> <p style={styles.text_medium}>No notes exist yet</p>
@ -44,30 +51,20 @@ export default function Notes() {
</div> </div>
); );
} }
return ( return (
<> <>
{notes.map( {notes.map((note: NoteProps, index: number) => {
( return (
note: { <Note
title: string; id={note.id}
content: string; key={index}
id: number; title={note.title}
date_created: string; content={note.content}
}, date_created={note.date_created}
index: number owner={note.owner}
) => { />
return ( );
<Note })}
id={note.id}
key={index}
title={note.title}
content={note.content}
date_created={note.date_created}
/>
);
}
)}
<Button <Button
style={styles.button_green} style={styles.button_green}
variant="contained" variant="contained"

View file

@ -0,0 +1,39 @@
import { Button } from "@mui/material";
import * as React from "react";
import { useNavigate } from "react-router-dom";
import { IconProps } from "../../Interfaces/Interfaces";
export default function UserIcon(props: IconProps) {
const navigate = useNavigate();
return (
<Button
variant="contained"
style={{
backgroundColor: "#005997",
borderRadius: 16,
width: props.size + "px",
height: props.size + "px",
margin: 4,
alignContent: "center",
alignItems: "center",
}}
onClick={() => navigate("/User")}
>
<svg
xmlns="http://www.w3.org/2000/svg"
width={props.size}
height={props.size}
viewBox="0 0 24 24"
strokeWidth="2"
stroke={props.color}
fill="none"
strokeLinecap="round"
strokeLinejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M12 7m-4 0a4 4 0 1 0 8 0a4 4 0 1 0 -8 0"></path>
<path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2"></path>
</svg>
</Button>
);
}

View file

@ -0,0 +1,58 @@
// Redux Interfaces
export interface LoginState {
Login: { logged_in: boolean };
}
export interface LoggedInUserState {
LoggedInUser: {
value: {
email: string;
id: number;
username: string;
};
};
}
// Component Props Interfaces
export interface NoteProps {
title: string;
content: string;
id: number;
date_created: Date;
owner: string;
}
export interface IconProps {
size: number;
color: string;
}
// API Interfaces
export interface RegistrationParams {
email: string;
username: string;
password: string;
}
export interface LoginParams {
username: string;
password: string;
}
export interface ActivationParams {
uid: string;
token: string;
}
export interface AddNoteParams {
title: string;
content: string;
}
export interface UpdateNoteParams {
id: number;
title: string;
content: string;
}

View file

@ -3,15 +3,12 @@ import Header from "../../Components/Header/Header";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { UserActivate } from "../../Components/Api/Api"; import { UserActivate } from "../../Components/Api/Api";
import { ActivationParams } from "../../Interfaces/Interfaces";
export interface activation {
uid: string;
token: string;
}
export default function Activation() { export default function Activation() {
let { uid, token } = useParams(); let { uid, token } = useParams();
const [status, setStatus] = useState(0); const [status, setStatus] = useState(0);
async function verify(activation: activation) { async function verify(activation: ActivationParams) {
let status = await UserActivate(activation); let status = await UserActivate(activation);
if (status) { if (status) {
setStatus(1); setStatus(1);
@ -23,7 +20,7 @@ export default function Activation() {
if (uid && token) { if (uid && token) {
verify({ uid, token }); verify({ uid, token });
} }
}, []); }, [uid, token]);
if (status === 1) { if (status === 1) {
return ( return (
<div style={styles.background}> <div style={styles.background}>

View file

@ -1,11 +1,11 @@
import styles from "../../styles"; import styles from "../../styles";
import Header from "../../Components/Header/Header"; import Header from "../../Components/Header/Header";
import NoteMapper from "../../Components/Notes/Notes"; import Notes from "../../Components/Notes/Notes";
export default function Home() { export default function Home() {
return ( return (
<div style={styles.background}> <div style={styles.background}>
<Header /> <Header />
<NoteMapper /> <Notes />
</div> </div>
); );
} }

View file

@ -7,7 +7,7 @@ import { useState } from "react";
import { Button } from "@mui/material"; import { Button } from "@mui/material";
import { UserInfo, UserLogin } from "../../Components/Api/Api"; import { UserInfo, UserLogin } from "../../Components/Api/Api";
import { useSelector, useDispatch } from "react-redux"; import { useDispatch } from "react-redux";
import { SetUser } from "../../Features/Redux/Slices/LoggedInUserSlice/LoggedInUserSlice"; import { SetUser } from "../../Features/Redux/Slices/LoggedInUserSlice/LoggedInUserSlice";
import { SetLoggedIn } from "../../Features/Redux/Slices/LoginSlice/LoginSlice"; import { SetLoggedIn } from "../../Features/Redux/Slices/LoginSlice/LoginSlice";
@ -29,7 +29,7 @@ export default function Login() {
<div style={{ margin: 4 }} /> <div style={{ margin: 4 }} />
<input <input
style={styles.input_notetitle} style={styles.input_notetitle}
onChange={(e: { target: { value: any } }) => { onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setUser({ ...user, username: e.target.value }); setUser({ ...user, username: e.target.value });
}} }}
maxLength={20} maxLength={20}
@ -41,7 +41,7 @@ export default function Login() {
<input <input
style={styles.input_notetitle} style={styles.input_notetitle}
type="password" type="password"
onChange={(e: { target: { value: any } }) => { onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setUser({ ...user, password: e.target.value }); setUser({ ...user, password: e.target.value });
}} }}
maxLength={20} maxLength={20}

View file

@ -42,8 +42,8 @@ export default function NewNote() {
<div style={styles.note_content}> <div style={styles.note_content}>
<textarea <textarea
style={styles.input_notebody} style={styles.input_notebody}
onChange={(e: { target: { value: any } }) => { onChange={async (e: { target: { value: any } }) => {
setNote({ ...note, content: e.target.value }); await setNote({ ...note, content: e.target.value });
}} }}
/> />
</div> </div>
@ -51,11 +51,13 @@ export default function NewNote() {
style={styles.button_green} style={styles.button_green}
variant="contained" variant="contained"
onClick={async () => { onClick={async () => {
mutation.mutate({ try {
title: note.title, await mutation.mutate({
content: note.content, title: note.title,
}); content: note.content,
navigate("/"); });
navigate("/");
} catch (error) {}
}} }}
> >
Add Note Add Note

View file

@ -1,16 +1,12 @@
import * as React from "react"; import * as React from "react";
import styles from "../../styles"; import styles from "../../styles";
import { useNavigate } from "react-router-dom";
import Header from "../../Components/Header/Header"; import Header from "../../Components/Header/Header";
import { useState } from "react"; import { useState } from "react";
import { Button } from "@mui/material"; import { Button } from "@mui/material";
import { UserInfo, UserLogin } from "../../Components/Api/Api";
import { UserRegister } from "../../Components/Api/Api"; import { UserRegister } from "../../Components/Api/Api";
export default function Register() { export default function Register() {
const navigate = useNavigate();
const [user, setUser] = useState({ const [user, setUser] = useState({
email: "", email: "",
username: "", username: "",
@ -27,7 +23,7 @@ export default function Register() {
<div style={{ margin: 4 }} /> <div style={{ margin: 4 }} />
<input <input
style={styles.input_notetitle} style={styles.input_notetitle}
onChange={(e: { target: { value: any } }) => { onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setUser({ ...user, email: e.target.value }); setUser({ ...user, email: e.target.value });
}} }}
maxLength={20} maxLength={20}
@ -38,7 +34,7 @@ export default function Register() {
<div style={{ margin: 4 }} /> <div style={{ margin: 4 }} />
<input <input
style={styles.input_notetitle} style={styles.input_notetitle}
onChange={(e: { target: { value: any } }) => { onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setUser({ ...user, username: e.target.value }); setUser({ ...user, username: e.target.value });
}} }}
maxLength={20} maxLength={20}
@ -50,7 +46,7 @@ export default function Register() {
<input <input
style={styles.input_notetitle} style={styles.input_notetitle}
type="password" type="password"
onChange={(e: { target: { value: any } }) => { onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setUser({ ...user, password: e.target.value }); setUser({ ...user, password: e.target.value });
}} }}
maxLength={20} maxLength={20}
@ -61,9 +57,7 @@ export default function Register() {
variant="contained" variant="contained"
onClick={async () => { onClick={async () => {
setUser({ setUser({
email: "", ...user,
username: "",
password: "",
}); });
if (await UserRegister(user)) { if (await UserRegister(user)) {
setFeedback( setFeedback(

View file

@ -0,0 +1,51 @@
import styles from "../../styles";
import Header from "../../Components/Header/Header";
import { UserInfo } from "../../Components/Api/Api";
import { useQuery } from "react-query";
import { useSelector } from "react-redux";
import { LoginState } from "../../Interfaces/Interfaces";
import LoginButton from "../../Components/LoginButton/LoginButton";
export default function UserPage() {
const { data, isLoading, error } = useQuery("user", UserInfo, { retry: 0 });
const logged_in = useSelector((state: LoginState) => state.Login.logged_in);
if (isLoading && !error) {
return (
<div style={styles.background}>
<Header />
<div style={styles.note}>
<p style={styles.text_medium}>Loading...</p>
</div>
</div>
);
} else if (!logged_in && error) {
return (
<div style={styles.background}>
<Header />
<div style={styles.note}>
<p style={styles.text_medium}>Please login to view user info</p>
<LoginButton />
</div>
</div>
);
} else if (error) {
return (
<div style={styles.background}>
<Header />
<div style={styles.note}>
<p style={styles.text_medium_red}>An error has occured</p>
</div>
</div>
);
}
return (
<div style={styles.background}>
<Header />
<div style={styles.note}>
<p style={styles.text_medium}>Username: {data.username}</p>
<p style={styles.text_medium}>Email: {data.email}</p>
<p style={styles.text_medium}>User ID: {data.id}</p>
</div>
</div>
);
}

View file

@ -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 (
<div style={styles.background}>
<Header />
<div style={styles.note}>
<p style={styles.text_medium_red}>Error retrieving specific note</p>
</div>
</div>
);
}
if (isLoading) {
return (
<div style={styles.note}>
<p style={styles.text_medium}>Loading Note...</p>
</div>
);
}
if (data) {
return (
<div style={styles.background}>
<Header />
<p style={styles.text_medium}>Edit Note</p>
<div style={styles.flex_column}>
<div style={styles.note}>
<div style={styles.flex_row}>
<p style={styles.text_small}>Title:&nbsp;</p>
<input
style={styles.input_notetitle}
value={note.title}
onChange={(e: { target: { value: any } }) => {
setNote({ ...note, title: e.target.value });
}}
maxLength={20}
/>
</div>
<div style={styles.note_content}>
<textarea
style={styles.input_notebody}
value={note.content}
onChange={async (e: { target: { value: any } }) => {
await setNote({ ...note, content: e.target.value });
}}
/>
</div>
<Button
style={styles.button_green}
variant="contained"
onClick={async () => {
try {
await mutation.mutate({
id: Number(id),
title: note.title,
content: note.content,
});
navigate("/");
} catch (error) {}
}}
>
Update Note
</Button>
</div>
</div>
<div style={styles.flex_row}>
<Button
style={styles.button_red}
variant="contained"
onClick={() => {
navigate("/");
}}
>
Cancel
</Button>
</div>
</div>
);
}
return <div>heh</div>;
}

View file

@ -9,6 +9,8 @@ import NewNote from "./Routes/NewNote/NewNote";
import Login from "./Routes/Login/Login"; import Login from "./Routes/Login/Login";
import Activation from "./Routes/Activation/Activation"; import Activation from "./Routes/Activation/Activation";
import Register from "./Routes/Register/Register"; import Register from "./Routes/Register/Register";
import UserPage from "./Routes/UserPage/UserPage";
import ViewEditNote from "./Routes/ViewEditNote/ViewEditNote";
import { QueryClient, QueryClientProvider } from "react-query"; import { QueryClient, QueryClientProvider } from "react-query";
@ -38,6 +40,14 @@ const router = createBrowserRouter([
path: "/Activation/:uid/:token", path: "/Activation/:uid/:token",
element: <Activation />, element: <Activation />,
}, },
{
path: "/Note/:id",
element: <ViewEditNote />,
},
{
path: "/User",
element: <UserPage />,
},
]); ]);
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(

View file

@ -47,6 +47,7 @@ const styles: { [key: string]: React.CSSProperties } = {
}, },
note_content: { note_content: {
display: "flex", display: "flex",
flexWrap: "wrap",
flexDirection: "column", flexDirection: "column",
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
@ -80,7 +81,8 @@ const styles: { [key: string]: React.CSSProperties } = {
height: "100%", height: "100%",
width: "100%", width: "100%",
minWidth: "100%", minWidth: "100%",
maxHeight: "200px", minHeight: "256px",
maxHeight: "768px",
fontSize: "2vh", fontSize: "2vh",
fontWeight: "bold", fontWeight: "bold",
}, },
@ -90,8 +92,7 @@ const styles: { [key: string]: React.CSSProperties } = {
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "row",
width: "256x", width: "256x",
marginTop: 4, margin: 4,
marginBottom: 4,
}, },
button_yellow: { button_yellow: {
backgroundColor: "#e2b465", backgroundColor: "#e2b465",
@ -99,8 +100,7 @@ const styles: { [key: string]: React.CSSProperties } = {
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "row",
width: "256px", width: "256px",
marginTop: 4, margin: 4,
marginBottom: 4,
}, },
button_red: { button_red: {
backgroundColor: "#bc231e", backgroundColor: "#bc231e",
@ -108,8 +108,7 @@ const styles: { [key: string]: React.CSSProperties } = {
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "row",
width: "256px", width: "256px",
marginTop: 4, margin: 4,
marginBottom: 4,
}, },
text_small: { text_small: {
color: "white", color: "white",