From 3cf1d03df418c5d3ed31a3965c577ea71e219a05 Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Sat, 16 Dec 2023 18:32:35 +0100 Subject: [PATCH] posts posting --- client/src/App.scss | 3 +- client/src/App.tsx | 34 +++++++---- client/src/Auth.scss | 26 ++++++++ client/src/Home.scss | 59 ++++++++++++++++++ client/src/Home.tsx | 45 ++++++++++---- client/src/Login.tsx | 2 +- client/src/Messages.tsx | 3 + client/src/Profile.scss | 60 +++++++++++++++++++ client/src/Profile.tsx | 43 +++++++++++++ client/src/ProfileCard.scss | 15 +++++ client/src/ProfileCard.tsx | 16 +++++ client/src/Signup.tsx | 2 +- client/src/actions.ts | 6 ++ client/src/api/Post.ts | 12 ++++ client/src/api/dto.ts | 16 +++++ client/src/index.scss | 13 ++++ client/src/index.tsx | 2 + client/src/loaders.ts | 37 +++++++++++- .../y/server/controller/PersonController.java | 2 +- 19 files changed, 368 insertions(+), 28 deletions(-) create mode 100644 client/src/Home.scss create mode 100644 client/src/Messages.tsx create mode 100644 client/src/Profile.scss create mode 100644 client/src/Profile.tsx create mode 100644 client/src/ProfileCard.scss create mode 100644 client/src/ProfileCard.tsx create mode 100644 client/src/api/Post.ts create mode 100644 client/src/index.scss diff --git a/client/src/App.scss b/client/src/App.scss index 6779299..7fa534a 100644 --- a/client/src/App.scss +++ b/client/src/App.scss @@ -1,6 +1,5 @@ #appRoot { font-family: sans-serif; max-width: 50rem; - margin-left: auto; - margin-right: auto; + margin: 0 auto; } \ No newline at end of file diff --git a/client/src/App.tsx b/client/src/App.tsx index 65890b9..406ec43 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -10,10 +10,13 @@ import { deleteToken, getToken } from "./api/utils"; import { Login } from "./Login"; import { Signup } from "./Signup"; import { Home } from "./Home"; -import { loginAction, signupAction } from "./actions"; -import { homeLoader } from "./loaders"; +import { loginAction, profileSelfAction, signupAction } from "./actions"; +import { homeLoader, profileSelfLoader } from "./loaders"; import { isError } from "./api/dto"; import { Feed } from "./Feed"; +import { Messages } from "./Messages"; +import { Profile } from "./Profile"; +import { getSelf } from "./api/Person"; const router = createBrowserRouter([ { @@ -29,18 +32,25 @@ const router = createBrowserRouter([ { path: "/home", loader: async () => { - if (getToken() == null) { - return redirect("/login"); - } - const ret = await homeLoader(); - if (isError(ret)) { - deleteToken(); - return redirect("/"); - } - return ret; + return await homeLoader(); }, element: , - children: [{ path: "feed", element: }], + children: [ + { path: "feed", element: }, + { path: "messages", element: }, + { + path: "profile", + loader: async () => { + return await profileSelfLoader(); + }, + action: profileSelfAction, + element: , + }, + { + path: "profile/:username", + element: , + }, + ], }, { path: "/login", diff --git a/client/src/Auth.scss b/client/src/Auth.scss index 33f288f..5410ac8 100644 --- a/client/src/Auth.scss +++ b/client/src/Auth.scss @@ -1,4 +1,30 @@ .authForm { + width: 20rem; + margin: 0 auto; + display: flex; + flex-direction: column; + padding: 2rem 0; + .errors { + margin: 2rem 0; + color: red; + } + + form { + display: flex; + flex-direction: column; + + * { + margin: 0.3rem 0; + } + + label { + margin-bottom: 0; + } + + input { + margin-top: 0; + } + } } \ No newline at end of file diff --git a/client/src/Home.scss b/client/src/Home.scss new file mode 100644 index 0000000..62251bd --- /dev/null +++ b/client/src/Home.scss @@ -0,0 +1,59 @@ +#Home { + display: flex; + flex-direction: row; + min-height: 100vh; + + #HomeSidebar { + min-width: 15rem; + min-height: 100vh; + border-right: solid gray 1px; + border-radius: 7px; + padding: 2rem 1rem; + + #SidebarUserInfo { + display: flex; + flex-direction: column; + } + + * { + margin: 0.5rem 0; + } + + #SidebarNav { + a { + color: black; + text-decoration: none; + + min-width: 100%; + height: 2rem; + + display: flex; + flex-direction: column; + justify-content: center; + text-align: left; + padding-left: 1rem; + font-size: 1.15rem; + + border-radius: 7px; + border: 1px solid #F0F0F0; + + &.active { + background-color: #EFEFEF; + } + + &.pending { + color: gray; + background-color: #FFFFFF; + } + + } + + } + } + + #HomeContent { + margin: 0; + min-width: 100%; + + } +} \ No newline at end of file diff --git a/client/src/Home.tsx b/client/src/Home.tsx index f76fe5d..538e600 100644 --- a/client/src/Home.tsx +++ b/client/src/Home.tsx @@ -1,21 +1,46 @@ -import { Outlet, useLoaderData } from "react-router-dom"; -import { homeLoader } from "./loaders"; +import { NavLink, NavLinkProps, Outlet, useLoaderData } from "react-router-dom"; +import { homeLoader, LoaderToType } from "./loaders"; import { isError } from "./api/dto"; +import "./Home.scss"; + export function Home() { - const loaderData = useLoaderData() as - | Awaited> - | undefined; + const loaderData = useLoaderData() as LoaderToType; if (!loaderData || isError(loaderData)) { return
Error
; } + const activePendingClassName = ({ + isActive, + isPending, + }: { + isActive: boolean; + isPending: boolean; + }) => (isActive ? "active" : isPending ? "pending" : ""); + return ( - <> - username: {loaderData.username} - name: {loaderData.fullName} - - +
+
+ +
+ + Feed + {" "} + + Messages + + + Profile + +
+
+
+ +
+
); } diff --git a/client/src/Login.tsx b/client/src/Login.tsx index 3288bc8..37f2161 100644 --- a/client/src/Login.tsx +++ b/client/src/Login.tsx @@ -25,7 +25,7 @@ export function Login() { return (
- {errors} +
{errors}
diff --git a/client/src/Messages.tsx b/client/src/Messages.tsx new file mode 100644 index 0000000..7024135 --- /dev/null +++ b/client/src/Messages.tsx @@ -0,0 +1,3 @@ +export function Messages() { + return Messages; +} diff --git a/client/src/Profile.scss b/client/src/Profile.scss new file mode 100644 index 0000000..dae793a --- /dev/null +++ b/client/src/Profile.scss @@ -0,0 +1,60 @@ +.profileView { + min-width: 100%; + display: flex; + flex-direction: column; + + .profileInfo { + min-width: 100%; + border-bottom: solid gray 1px; + border-right: solid gray 1px; + border-bottom-right-radius: 7px; + padding: 2rem; + + display: flex; + flex-direction: column; + + .fullName { + font-size: 1.5rem; + } + + .username { + + } + + } + + .newPost { + display: flex; + flex-direction: column; + margin: 2rem; + min-height: 6rem; + + border: solid gray 1px; + border-radius: 7px; + + form { + min-height: 100%; + display: flex; + flex-direction: row; + flex: auto; + + textarea { + flex-grow: 1; + border: 0px; + border-radius: 7px 0 0 7px; + padding: 7px; + resize: none; + } + + button { + border: 0px; + border-radius: 0 7px 7px 0; + } + + } + } + + .posts { + padding: 2rem; + } +} \ No newline at end of file diff --git a/client/src/Profile.tsx b/client/src/Profile.tsx new file mode 100644 index 0000000..bcf4974 --- /dev/null +++ b/client/src/Profile.tsx @@ -0,0 +1,43 @@ +import "./Profile.scss"; +import { Form, Link, useLoaderData } from "react-router-dom"; +import { LoaderToType, profileSelfLoader } from "./loaders"; +import { isError } from "./api/dto"; +import { ProfileCard } from "./ProfileCard"; + +export interface IProfileProps { + self: boolean; +} + +export function Profile(props: IProfileProps) { + const loaderData = useLoaderData() as LoaderToType< + typeof profileSelfLoader + >; + + if (!loaderData || isError(loaderData)) { + return
Error
; + } + return ( +
+
+ {loaderData.user.fullName} + {loaderData.user.fullName} +
+
+ +