From 7a1644690dde4f19a2c6faafc35e1b03c4e3eef1 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Sat, 9 Jan 2021 01:06:17 +0200 Subject: [PATCH] link to free agent post --- components/u/AvatarWithInfo.tsx | 31 +++++++- pages/freeagents.tsx | 101 +++++++++++++++++--------- pages/u/[identifier].tsx | 2 +- prisma/queries/getUserByIdentifier.ts | 3 + 4 files changed, 96 insertions(+), 41 deletions(-) diff --git a/components/u/AvatarWithInfo.tsx b/components/u/AvatarWithInfo.tsx index db19246cc..7095c20d8 100644 --- a/components/u/AvatarWithInfo.tsx +++ b/components/u/AvatarWithInfo.tsx @@ -20,7 +20,7 @@ import useUser from "lib/useUser"; import { GetUserByIdentifierData } from "prisma/queries/getUserByIdentifier"; import { FaGamepad, FaTwitch, FaTwitter, FaYoutube } from "react-icons/fa"; import { FiInfo } from "react-icons/fi"; -import { RiTrophyLine } from "react-icons/ri"; +import { RiFileTextLine, RiTrophyLine } from "react-icons/ri"; interface AvatarWithInfoProps { user: NonNullable; @@ -181,18 +181,41 @@ const AvatarWithInfo: React.FC = ({ )} - + {!!user.player?.switchAccountId && ( - )} - + {!!user.freeAgentPost?.id && ( + + + + )} + diff --git a/pages/freeagents.tsx b/pages/freeagents.tsx index 7732b49c4..9c4223980 100644 --- a/pages/freeagents.tsx +++ b/pages/freeagents.tsx @@ -26,8 +26,9 @@ import { sendData } from "lib/postData"; import { Unpacked } from "lib/types"; import { useMyTheme } from "lib/useMyTheme"; import useUser from "lib/useUser"; +import { useRouter } from "next/router"; import { GetAllFreeAgentPostsData } from "prisma/queries/getAllFreeAgentPosts"; -import { useState } from "react"; +import { RefObject, useEffect, useRef, useState } from "react"; import { FaHeart, FaRegHeart } from "react-icons/fa"; import { RiAnchorLine, @@ -37,9 +38,28 @@ import { } from "react-icons/ri"; const FreeAgentsPage = () => { - const { data, usersPost, playstyleCounts, state, dispatch } = useFreeAgents(); + const { + data, + isLoading, + usersPost, + playstyleCounts, + state, + dispatch, + } = useFreeAgents(); + const router = useRouter(); + const postRef = useRef(null); const [modalIsOpen, setModalIsOpen] = useState(false); + const idToScrollTo = Number.isNaN(parseInt(router.query.id as any)) + ? undefined + : parseInt(router.query.id as any); + + useEffect(() => { + if (!postRef.current) return; + + postRef.current.scrollIntoView(); + }, [postRef.current]); + return ( {modalIsOpen && ( @@ -53,40 +73,47 @@ const FreeAgentsPage = () => { New free agent post )} -
- - dispatch({ - type: "SET_PLAYSTYLE", - playstyle: value === "ALL" ? undefined : (value as Playstyle), - }) - } - > - - - - All ( - {playstyleCounts.FRONTLINE + - playstyleCounts.MIDLINE + - playstyleCounts.BACKLINE} - ) - - - - Frontline ({playstyleCounts.FRONTLINE}) - - - Support ({playstyleCounts.MIDLINE}) - - - Backline ({playstyleCounts.BACKLINE}) - - - -
+ {!isLoading && ( +
+ + dispatch({ + type: "SET_PLAYSTYLE", + playstyle: value === "ALL" ? undefined : (value as Playstyle), + }) + } + > + + + + All ( + {playstyleCounts.FRONTLINE + + playstyleCounts.MIDLINE + + playstyleCounts.BACKLINE} + ) + + + + Frontline ({playstyleCounts.FRONTLINE}) + + + Support ({playstyleCounts.MIDLINE}) + + + Backline ({playstyleCounts.BACKLINE}) + + + +
+ )} {data.map((post) => ( - + ))}
); @@ -101,9 +128,11 @@ const playstyleToEmoji = { const FreeAgentCard = ({ post, isLiked, + postRef, }: { post: Unpacked; isLiked: boolean; + postRef?: RefObject; }) => { const { themeColorShade } = useMyTheme(); const [user] = useUser(); @@ -114,7 +143,7 @@ const FreeAgentCard = ({ return ( <> - + diff --git a/pages/u/[identifier].tsx b/pages/u/[identifier].tsx index e9213717f..809f3c680 100644 --- a/pages/u/[identifier].tsx +++ b/pages/u/[identifier].tsx @@ -87,7 +87,7 @@ const ProfilePage = (props: Props) => { <> - + )} diff --git a/prisma/queries/getUserByIdentifier.ts b/prisma/queries/getUserByIdentifier.ts index 8e5f188d5..27df8dbeb 100644 --- a/prisma/queries/getUserByIdentifier.ts +++ b/prisma/queries/getUserByIdentifier.ts @@ -48,5 +48,8 @@ export const getUserByIdentifier = (identifier: string) => switchAccountId: true, }, }, + freeAgentPost: { + select: { id: true }, + }, }, });