11import React , { useState } from "react" ;
2+ import { SignInButton , useAuth , UserButton } from "@clerk/nextjs" ;
3+ import type { PostType } from "@prisma/client" ;
24
3- import NavBar from "~/components/navbar" ;
45import { api } from "~/utils/api" ;
56import Post from "../components/post" ;
7+ import ToggleButton from "../components/ToggleButton" ;
8+
9+ interface PostData {
10+ id : number ;
11+ title : string ;
12+ content : string ;
13+ createdAt : Date ;
14+ userId : number ;
15+ images : string [ ] ;
16+ postType : PostType ;
17+ comments : {
18+ id : number ;
19+ userId : number ;
20+ createdAt : Date ;
21+ postId : number ;
22+ text : string ;
23+ } [ ] ;
24+ contents : string | null ;
25+ }
626
727function Posts ( ) {
8- const posts = api . discussion . getDiscussions . useQuery ( ) ;
9- const userPosts = api . discussion . getDiscussionsByUser . useQuery ( ) ;
28+ const posts = api . discussion . getDiscussions . useQuery < PostData [ ] > ( ) ;
29+ const userPosts = api . discussion . getDiscussionsByUser . useQuery < PostData [ ] > ( ) ;
1030
1131 const [ myPostToggle , setMyPostToggle ] = useState ( true ) ;
1232
@@ -18,44 +38,46 @@ function Posts() {
1838 setMyPostToggle ( false ) ;
1939 } ;
2040
41+ const { isSignedIn } = useAuth ( ) ;
42+
2143 return (
2244 < div className = "absolute bottom-0 top-0 flex w-full" >
23- < NavBar />
45+ < div className = "sticky top-0 flex max-w-[40%] flex-col justify-between bg-[#EFF2FB] p-4" >
46+ { isSignedIn ? "" : < SignInButton /> }
47+ < UserButton afterSignOutUrl = "/" showName />
48+ < nav className = "flex flex-col" >
49+ < button className = "m-2 rounded-3xl border border-[#2E4D90] bg-[#2E4D90] p-2 text-white" >
50+ < a href = "/posts/" > Forum</ a >
51+ </ button >
52+ < button className = "m-2 rounded-3xl border border-[#2E4D90] p-2" >
53+ < a href = "/announcements/" > Announcements</ a >
54+ </ button >
55+ < button className = "m-2 rounded-3xl border border-[#2E4D90] p-2" >
56+ < a href = "/absences/" > Absentees</ a >
57+ </ button >
58+ < button className = "m-2 rounded-3xl border border-[#2E4D90] p-2" >
59+ < a href = "/activities/" > Calendar</ a >
60+ </ button >
61+ < button className = "m-2 rounded-3xl border border-[#2E4D90] p-2" >
62+ < a href = "/activities/" > Invite New User</ a >
63+ </ button >
64+ </ nav >
65+ < button className = "m-2 rounded-3xl border border-[#2E4D90] p-2" >
66+ < a href = "/activities/" > Create New</ a >
67+ </ button >
68+ </ div >
2469 < div className = "flex w-full flex-col items-center pt-6" >
25- < div className = "m-2 w-max self-center rounded-3xl border border-[#2E4D90]" >
26- { myPostToggle ? (
27- < >
28- < button className = "rounded-3xl px-10 py-2" onClick = { setAllPosts } >
29- All Posts
30- </ button >
31- < button
32- className = "rounded-3xl bg-[#2E4D90] px-10 py-2 text-white"
33- onClick = { setMyPosts }
34- >
35- My Posts
36- </ button >
37- </ >
38- ) : (
39- < >
40- < button
41- className = "rounded-3xl bg-[#2E4D90] px-10 py-2 text-white"
42- onClick = { setAllPosts }
43- >
44- All Posts
45- </ button >
46- < button className = "rounded-3xl px-10 py-2" onClick = { setMyPosts } >
47- My Posts
48- </ button >
49- </ >
50- ) }
51- </ div >
70+ < ToggleButton
71+ word = "Posts"
72+ isToggled = { myPostToggle }
73+ setAll = { setAllPosts }
74+ setMy = { setMyPosts }
75+ />
5276 { myPostToggle
53- ? userPosts . data ?. map ( ( p ) => {
54- // get user name from id and pass it in
77+ ? userPosts . data ?. map ( ( p : PostData ) => {
5578 return < Post key = { p . id } { ...p } /> ;
5679 } )
57- : posts . data ?. map ( ( p ) => {
58- // get user name from id and pass it in
80+ : posts . data ?. map ( ( p : PostData ) => {
5981 return < Post key = { p . id } { ...p } /> ;
6082 } ) }
6183 </ div >
0 commit comments