diff --git a/backend/routes/user/get_user.go b/backend/routes/user/get_user.go index 825c40c..c7edfac 100644 --- a/backend/routes/user/get_user.go +++ b/backend/routes/user/get_user.go @@ -90,3 +90,27 @@ func (s *Server) getUser(w http.ResponseWriter, r *http.Request) error { render.JSON(w, r, dbUserToResponse(u, fields)) return nil } + +func (s *Server) getMeUser(w http.ResponseWriter, r *http.Request) error { + ctx := r.Context() + claims, _ := server.ClaimsFromContext(ctx) + + u, err := s.DB.User(ctx, claims.UserID) + if err != nil { + log.Errorf("Error getting user: %v", err) + return err + } + + fields, err := s.DB.UserFields(ctx, u.ID) + if err != nil { + log.Errorf("Error getting user fields: %v", err) + return err + } + + render.JSON(w, r, GetMeResponse{ + GetUserResponse: dbUserToResponse(u, fields), + Discord: u.Discord, + DiscordUsername: u.DiscordUsername, + }) + return nil +} diff --git a/backend/routes/user/routes.go b/backend/routes/user/routes.go index a190805..fda9f9c 100644 --- a/backend/routes/user/routes.go +++ b/backend/routes/user/routes.go @@ -13,7 +13,7 @@ func Mount(srv *server.Server, r chi.Router) { s := &Server{srv} r.Route("/users", func(r chi.Router) { - r.With(server.MustAuth).Get("/@me", server.WrapHandler(nil)) + r.With(server.MustAuth).Get("/@me", server.WrapHandler(s.getMeUser)) r.Get("/{userRef}", server.WrapHandler(s.getUser)) }) diff --git a/frontend/src/lib/Card.tsx b/frontend/src/lib/Card.tsx new file mode 100644 index 0000000..22d9c99 --- /dev/null +++ b/frontend/src/lib/Card.tsx @@ -0,0 +1,14 @@ +import React, { PropsWithChildren } from "react"; + +export type Props = PropsWithChildren<{ title: string }>; + +export default function Card({ title, children }: Props) { + return ( +
+

+ {title} +

+
{children}
+
+ ); +} diff --git a/frontend/src/lib/FieldCard.tsx b/frontend/src/lib/FieldCard.tsx index a06dc3c..830c369 100644 --- a/frontend/src/lib/FieldCard.tsx +++ b/frontend/src/lib/FieldCard.tsx @@ -6,39 +6,37 @@ import { EmojiLaughing, } from "react-bootstrap-icons"; +import Card from "./Card"; import type { Field } from "./types"; export default function FieldCard({ field }: { field: Field }) { return ( -
-

{field.name}

-
- {field.favourite.map((entry) => ( -

- {entry} -

- ))} - {field.okay.length !== 0 && ( -

- {field.okay.join(", ")} -

- )} - {field.jokingly.length !== 0 && ( -

- {field.jokingly.join(", ")} -

- )} - {field.friends_only.length !== 0 && ( -

- {field.friends_only.join(", ")} -

- )} - {field.avoid.length !== 0 && ( -

- {field.avoid.join(", ")} -

- )} -
-
+ + {field.favourite.map((entry) => ( +

+ {entry} +

+ ))} + {field.okay.length !== 0 && ( +

+ {field.okay.join(", ")} +

+ )} + {field.jokingly.length !== 0 && ( +

+ {field.jokingly.join(", ")} +

+ )} + {field.friends_only.length !== 0 && ( +

+ {field.friends_only.join(", ")} +

+ )} + {field.avoid.length !== 0 && ( +

+ {field.avoid.join(", ")} +

+ )} +
); } diff --git a/frontend/src/lib/Navigation.tsx b/frontend/src/lib/Navigation.tsx index 6b127d7..abceeeb 100644 --- a/frontend/src/lib/Navigation.tsx +++ b/frontend/src/lib/Navigation.tsx @@ -45,7 +45,7 @@ function Navigation() { const nav = user ? ( <> - @{user.username} + @{user.username} Settings Log out diff --git a/frontend/src/lib/store.ts b/frontend/src/lib/store.ts index 50d8ee4..3b88310 100644 --- a/frontend/src/lib/store.ts +++ b/frontend/src/lib/store.ts @@ -27,3 +27,8 @@ async function getCurrentUser() { return null; } + +export function isMeUser(id: string): boolean { + const meUser = useRecoilValue(userState); + return meUser && meUser.id === id; +} diff --git a/frontend/src/pages/User.tsx b/frontend/src/pages/User.tsx index 3f23044..6d5bed1 100644 --- a/frontend/src/pages/User.tsx +++ b/frontend/src/pages/User.tsx @@ -1,17 +1,22 @@ import React, { useState, useEffect } from "react"; -import { useParams } from "react-router-dom"; +import { Link, useParams } from "react-router-dom"; import { ArrowClockwise } from "react-bootstrap-icons"; import ReactMarkdown from "react-markdown"; import { Helmet } from "react-helmet"; -import type { APIError, User } from "../lib/types"; +import NavItem from "../lib/NavItem"; +import type { User } from "../lib/types"; import fetchAPI from "../lib/fetch"; import FieldCard from "../lib/FieldCard"; +import Card from "../lib/Card"; +import { userState } from "../lib/store"; +import { useRecoilValue } from "recoil"; function UserPage() { const params = useParams(); const [user, setUser] = useState(null); + const meUser = useRecoilValue(userState); useEffect(() => { fetchAPI(`/users/${params.username}`).then((res) => { @@ -33,13 +38,25 @@ function UserPage() { @{user.username} - pronouns.cc + {meUser && meUser.id === user.id && ( +
+ + You are currently viewing your{" "} + public profile. + +
+ + Edit your profile + +
+ )}
-
+
{user.avatar_url && ( - + )}
{user.display_name && ( @@ -59,7 +76,7 @@ function UserPage() { {user.bio} )} - {user.links.length !== 0 && ( + {user.links.length !== 0 && user.fields.length === 0 && (
diff --git a/frontend/src/pages/login/Discord.tsx b/frontend/src/pages/login/Discord.tsx index 2adc20d..3388f88 100644 --- a/frontend/src/pages/login/Discord.tsx +++ b/frontend/src/pages/login/Discord.tsx @@ -67,5 +67,9 @@ export default function Discord() { navigate("/"); } + if (user || state.isLoading) { + return <>Loading...; + } + return <>wow such login; }