1
- "use client ";
1
+ import { useState , useCallback , useMemo } from "react ";
2
2
import { useCurrentUser } from "@/hooks/user" ;
3
3
import { CredentialResponse , GoogleLogin } from "@react-oauth/google" ;
4
4
import { BiCheckCircle , BiHash , BiHomeCircle , BiUser } from "react-icons/bi" ;
5
5
import { BsBell , BsBookmark , BsEnvelope , BsTwitter } from "react-icons/bs" ;
6
6
import { SlOptions } from "react-icons/sl" ;
7
7
import { graphqlClient } from "@/clients/api" ;
8
8
import { verifyUserGoogleTokenQuery } from "@/graphql/query/user" ;
9
- import { useCallback , useMemo } from "react" ;
10
9
import toast from "react-hot-toast" ;
11
10
import { useQueryClient } from "@tanstack/react-query" ;
12
11
import Link from "next/link" ;
@@ -24,6 +23,7 @@ interface TwitterSidebarButton {
24
23
export default function TwitterLayout ( { children } : TwitterLayoutProps ) {
25
24
const queryClient = useQueryClient ( ) ;
26
25
const { user } = useCurrentUser ( ) ;
26
+ const [ isDropdownOpen , setIsDropdownOpen ] = useState ( false ) ;
27
27
28
28
const sidebarMenuItems : TwitterSidebarButton [ ] = useMemo (
29
29
( ) => [
@@ -93,10 +93,17 @@ export default function TwitterLayout({ children }: TwitterLayoutProps) {
93
93
[ queryClient ]
94
94
) ;
95
95
96
+ const handleLogout = ( ) => {
97
+ window . localStorage . removeItem ( "__twitter_token" ) ;
98
+ queryClient . invalidateQueries ( { queryKey : [ "currentUser" ] } ) ;
99
+ setIsDropdownOpen ( false ) ;
100
+ toast . success ( "Logged out successfully" ) ;
101
+ } ;
102
+
96
103
return (
97
104
< div >
98
105
< div className = "grid grid-cols-12 h-screen w-screen lg:px-56" >
99
- < div className = "col-span-2 sm:col-span-3 pt-1 flex relative sm:justify-end pr-4" >
106
+ < div className = "col-span-2 sm:col-span-3 pt-1 relative pr-4" >
100
107
< div >
101
108
< div className = "text-2xl h-fit hover:bg-gray-800 rounded-full p-4 cursor-pointer transition-all w-fit" >
102
109
< Link href = { "/" } >
@@ -127,26 +134,55 @@ export default function TwitterLayout({ children }: TwitterLayoutProps) {
127
134
</ div >
128
135
</ div >
129
136
</ div >
137
+
130
138
{ user && (
131
- < div className = " absolute bottom-5 flex gap-2 items-center bg-slate-700 rounded-full px-3 py-2 cursor-pointer" >
132
- { user && user . profileImageURL && (
133
- < img
134
- src = { user . profileImageURL }
135
- alt = "User profile"
136
- height = { 50 }
137
- width = { 50 }
138
- className = "rounded-full"
139
- />
140
- ) }
141
- < div className = "hidden lg:block" >
142
- < h3 > { user . firstName } </ h3 >
139
+ < div className = "absolute bottom-5" >
140
+ < div
141
+ className = "bg-slate-700 rounded-full px-3 py-2 cursor-pointer w-full"
142
+ onClick = { ( ) => setIsDropdownOpen ( ! isDropdownOpen ) }
143
+ >
144
+ < div className = "flex items-center" >
145
+ { user . profileImageURL ? (
146
+ < img
147
+ src = { user . profileImageURL }
148
+ alt = "User profile"
149
+ height = { 50 }
150
+ width = { 50 }
151
+ className = "rounded-full"
152
+ />
153
+ ) : (
154
+ < div className = "h-10 w-10 bg-green-700 rounded-full flex items-center justify-center" >
155
+ < span className = "text-white font-semibold" >
156
+ { user . firstName . charAt ( 0 ) }
157
+ </ span >
158
+ </ div >
159
+ ) }
160
+ < span className = "hidden lg:inline ml-2 text-white" >
161
+ { user . firstName }
162
+ </ span >
163
+ </ div >
143
164
</ div >
165
+
166
+ { isDropdownOpen && (
167
+ < div className = "absolute bottom-16 left-0 bg-slate-700 p-3 rounded-lg w-48 shadow-lg" >
168
+ < ul >
169
+ < li
170
+ className = "cursor-pointer hover:bg-gray-600 p-2 rounded-lg"
171
+ onClick = { handleLogout }
172
+ >
173
+ Logout
174
+ </ li >
175
+ </ ul >
176
+ </ div >
177
+ ) }
144
178
</ div >
145
179
) }
146
180
</ div >
181
+
147
182
< div className = "col-span-10 sm:col-span-5 border-l-[1px] border-r-[1px] h-screen overflow-scroll scroll border-gray-600 no-scrollbar" >
148
183
{ children }
149
184
</ div >
185
+
150
186
< div className = "sm:col-span-3 p-5" >
151
187
{ ! user && (
152
188
< div className = "p-5 bg-slate-700 rounded-lg flex flex-col items-center" >
0 commit comments