@@ -65,10 +81,7 @@ const Editor = forwardRef((props: TEditor) => {
value={value}
ref={editor}
modules={modules}
-
onChange={changeHandler}
-
-
theme="snow"
placeholder="Type your thoughts here..."
/>
diff --git a/enshi/src/Pages/LoginRegisterPage/LoginPage/LoginPage.tsx b/enshi/src/Pages/LoginRegisterPage/LoginPage/LoginPage.tsx
index 7835c87..2b1e3db 100644
--- a/enshi/src/Pages/LoginRegisterPage/LoginPage/LoginPage.tsx
+++ b/enshi/src/Pages/LoginRegisterPage/LoginPage/LoginPage.tsx
@@ -33,6 +33,7 @@ export default function LoginPage() {
setUserAtom({
username: response.data.username,
isAdmin: false,
+ id: response.data.id,
});
},
@@ -48,6 +49,7 @@ export default function LoginPage() {
setUserAtom({
username: userAtomValue?.username || "",
isAdmin: true,
+ id: userAtomValue?.id,
});
}
};
diff --git a/enshi/src/Pages/LoginRegisterPage/PostRedactor/PostRedactor.tsx b/enshi/src/Pages/LoginRegisterPage/PostRedactor/PostRedactor.tsx
new file mode 100644
index 0000000..c7cafaa
--- /dev/null
+++ b/enshi/src/Pages/LoginRegisterPage/PostRedactor/PostRedactor.tsx
@@ -0,0 +1,75 @@
+import { Box, Container, Flex, Spinner } from "@radix-ui/themes";
+import { useQuery } from "@tanstack/react-query";
+import { useState } from "react";
+import { useParams } from "react-router-dom";
+import { axiosLocalhost } from "../../../api/axios/axios";
+import Editor from "../../../Components/Editor/Editor";
+import SubmitChangesButton from "./SubmitChangesButton/SubmitChangesButton";
+
+export default function PostRedactor() {
+ const [contentValue, setContentValue] = useState("");
+ const [titleValue, setTitleValue] = useState("");
+
+ const queryParams = useParams();
+
+ const { isPending } = useQuery({
+ queryKey: ["changePostKey", queryParams.postId],
+ queryFn: async () => {
+ try {
+ const response = await axiosLocalhost.get(
+ `/posts/${queryParams.postId}`
+ );
+
+ setTitleValue(response.data["title"]);
+ setContentValue(response.data["content"]);
+
+ return response.data;
+ } catch (error) {
+ console.log(error);
+
+ return error;
+ }
+ },
+ gcTime: Infinity,
+ });
+
+ return (
+ <>
+
+
+
+ {
+ setTitleValue(e.target.value);
+ }}
+ value={titleValue}
+ />
+
+
+
+ {isPending ? (
+
+ ) : (
+
+ )}
+
+
+
+
+
+
+
+ >
+ );
+}
diff --git a/enshi/src/Pages/LoginRegisterPage/PostRedactor/SubmitChangesButton/SubmitChangesButton.tsx b/enshi/src/Pages/LoginRegisterPage/PostRedactor/SubmitChangesButton/SubmitChangesButton.tsx
new file mode 100644
index 0000000..52cddc8
--- /dev/null
+++ b/enshi/src/Pages/LoginRegisterPage/PostRedactor/SubmitChangesButton/SubmitChangesButton.tsx
@@ -0,0 +1,57 @@
+import { Button } from "@radix-ui/themes";
+import { useMutation } from "@tanstack/react-query";
+import { useState } from "react";
+import { useTranslation } from "react-i18next";
+import { useNavigate, useParams } from "react-router-dom";
+import { axiosLocalhost } from "../../../../api/axios/axios";
+
+type TSubmitChangesButton = {
+ className: string;
+ titleValue: string;
+ contentValue: string;
+};
+
+export default function SubmitChangesButton(props: TSubmitChangesButton) {
+ const { t } = useTranslation();
+
+ const [isDisabled, setIsDisabled] = useState(false);
+
+ const navigate = useNavigate();
+ const queryParams = useParams();
+
+ const postMutation = useMutation({
+ mutationFn: async () => {
+ if (!props.titleValue) throw new Error("no title provided");
+ if (!props.contentValue || props.contentValue === "
")
+ throw new Error("no content provided");
+
+ axiosLocalhost.put(`/posts/${queryParams["postId"]}`, {
+ title: props.titleValue,
+ content: props.contentValue,
+ });
+ },
+ onMutate: () => {
+ setIsDisabled(true);
+ },
+ onError: () => {
+ setIsDisabled(false);
+ },
+ onSuccess: () => {
+ navigate("/");
+ },
+ });
+
+ return (
+
+ );
+}
diff --git a/enshi/src/Pages/LoginRegisterPage/RegisterPage/RegisterPage.tsx b/enshi/src/Pages/LoginRegisterPage/RegisterPage/RegisterPage.tsx
index bd488f4..787d581 100644
--- a/enshi/src/Pages/LoginRegisterPage/RegisterPage/RegisterPage.tsx
+++ b/enshi/src/Pages/LoginRegisterPage/RegisterPage/RegisterPage.tsx
@@ -34,7 +34,8 @@ export default function RegisterPage() {
let response = await axiosLocalhost.post("/users", JSON.stringify(data));
setUserAtom({
username: response.data.username,
- isAdmin: false
+ isAdmin: false,
+ id: response.data.id,
})
},
diff --git a/enshi/src/Pages/MainPage/MainPage.tsx b/enshi/src/Pages/MainPage/MainPage.tsx
index 12bb82d..bf710a8 100644
--- a/enshi/src/Pages/MainPage/MainPage.tsx
+++ b/enshi/src/Pages/MainPage/MainPage.tsx
@@ -24,6 +24,7 @@ export default function MainPage() {
setUserData({
isAdmin: response.data["is_admin"],
username: response.data["username"],
+ id: response.data["id"],
});
return true;
} catch (error) {
diff --git a/enshi/src/routes/routes.tsx b/enshi/src/routes/routes.tsx
index fd1c62a..a8f2323 100644
--- a/enshi/src/routes/routes.tsx
+++ b/enshi/src/routes/routes.tsx
@@ -7,6 +7,7 @@ import {
import ArticleViewer from "../Components/ArticleViewer/ArticleViewer";
import AuthPageWrapper from "../Pages/AuthPageWrapper/AuthPageWrapper";
import LoginPage from "../Pages/LoginRegisterPage/LoginPage/LoginPage";
+import PostRedactor from "../Pages/LoginRegisterPage/PostRedactor/PostRedactor";
import RegisterPage from "../Pages/LoginRegisterPage/RegisterPage/RegisterPage";
import MainPage from "../Pages/MainPage/MainPage";
import PostCreatorPage from "../Pages/PostCreatorPage/PostCreatorPage";
@@ -40,6 +41,7 @@ export const routes = createRoutesFromElements(
/>
} />
+
} />