Skip to content

Commit dc42241

Browse files
committed
Merge branch 'zouhir-auth' into feat-streaks
2 parents 3629657 + f62c62e commit dc42241

15 files changed

Lines changed: 87 additions & 135 deletions

File tree

src/components/Layout/Header.tsx

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { CgTab } from 'react-icons/cg'
44
import { FaUser } from 'react-icons/fa'
55
import { IoMdSunny } from 'react-icons/io'
66
import { MdDoDisturbOff, MdFlashOn } from 'react-icons/md'
7-
import { RxArrowLeft } from 'react-icons/rx'
87
import { Link, useLocation, useNavigate } from 'react-router-dom'
98
import { ReactComponent as HackertabLogo } from 'src/assets/logo.svg'
109
import { SearchBar } from 'src/components/Elements/SearchBar'
@@ -51,16 +50,6 @@ export const Header = () => {
5150
navigate('/settings/general')
5251
}
5352

54-
const BookmarksBadgeCount = () => {
55-
return userBookmarks.length > 0 ? (
56-
userBookmarks.length < 10 ? (
57-
<span className="badgeCount">{userBookmarks.length}</span>
58-
) : (
59-
<span className="badgeCount">+9</span>
60-
)
61-
) : null
62-
}
63-
6453
const onUnpauseClicked = () => {
6554
trackDNDDisable()
6655
setDNDDuration('never')
@@ -100,7 +89,7 @@ export const Header = () => {
10089
className="profileImageContainer"
10190
onClick={() => {
10291
if (isConnected()) {
103-
navigate('/settings/profile')
92+
navigate('/settings/general')
10493
} else {
10594
openAuthModal()
10695
}
@@ -119,15 +108,7 @@ export const Header = () => {
119108
)}
120109
</CircleButton>
121110
</div>
122-
{location.pathname === '/' ? (
123-
<UserTags />
124-
) : (
125-
<div className="backToHome">
126-
<Link to="/">
127-
<RxArrowLeft size={20} /> Back
128-
</Link>
129-
</div>
130-
)}
111+
{location.pathname === '/' && <UserTags />}
131112
</header>
132113
</>
133114
)

src/components/Layout/SettingsLayout/SettingsLayout.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import './settings.css'
55

66
export const SettingsLayout = () => {
77
const navigation = [
8-
{
9-
name: 'Profile',
10-
path: '/settings/profile',
11-
},
128
{
139
name: 'Topics',
1410
path: '/settings/topics',

src/features/auth/components/AuthModal.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuthProvider, OAuthProvider, signInWithPopup } from 'firebase/auth'
1+
import { AuthProvider, signInWithPopup } from 'firebase/auth'
22
import { FaGithub } from 'react-icons/fa'
33
import { FcGoogle } from 'react-icons/fc'
44
import { IoHeartCircle } from 'react-icons/io5'
@@ -19,21 +19,17 @@ export const AuthModal = ({ showAuth }: AuthModalProps) => {
1919
const signIn = (provider: AuthProvider) => {
2020
signInWithPopup(firebaseAuth, provider)
2121
.then((result) => {
22-
const credential = OAuthProvider.credentialFromResult(result)
23-
const idToken = credential?.idToken
24-
const email = result.user.displayName
2522
const name = result.user.displayName
2623
const imageURL = result.user.photoURL
27-
if (idToken && name && email && imageURL) {
24+
if (name && imageURL) {
2825
trackUserConnect(provider.providerId)
2926
closeAuthModal()
3027
initState({
31-
idToken: idToken,
3228
user: {
3329
name: name,
34-
email: email,
3530
imageURL: imageURL,
3631
},
32+
providerId: provider.providerId,
3733
})
3834
}
3935
})

src/features/auth/hooks/useAuth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { trackUserDisconnect } from 'src/lib/analytics'
44
export const useAuth = () => {
55
const { isAuthModalOpen, openAuthModal, closeAuthModal } = AuthModalStore()
66
const authStore = AuthStore()
7-
const { idToken, user, initState, clear } = authStore
7+
const { user, providerId, initState, clear } = authStore
88

99
const isConnected = () => user != null
1010

@@ -20,7 +20,7 @@ export const useAuth = () => {
2020
isConnected,
2121
logout,
2222
isAuthModalOpen,
23-
idToken,
2423
user,
24+
providerId,
2525
}
2626
}

src/features/auth/stores/authStore.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { create } from 'zustand'
33
import { persist } from 'zustand/middleware'
44

55
type AuthState = {
6-
idToken: string | null
76
user: User | null
7+
providerId: string | null
88
}
99

1010
type AuthActions = {
@@ -16,13 +16,12 @@ type AuthActions = {
1616
export const AuthStore = create(
1717
persist<AuthState & AuthActions>(
1818
(set) => ({
19-
idToken: null,
2019
user: null,
21-
20+
providerId: null,
2221
initState: (newState: AuthState) =>
2322
set({
24-
idToken: newState.idToken,
2523
user: newState.user,
24+
providerId: newState.providerId,
2625
}),
2726
setStreak: (streak: number) =>
2827
set((state) => ({

src/features/auth/types/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export type User = {
22
name: string
3-
email: string
43
imageURL?: string
54
streak?: number
65
}

src/features/settings/components/AddSearchEngine.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState } from 'react'
22
import { isValidURL } from 'src/utils/UrlUtils'
33

44
import { TiPlus } from 'react-icons/ti'
5+
import { Button } from 'src/components/Elements'
56
import { useUserPreferences } from 'src/stores/preferences'
67

78
export const AddSearchEngine = () => {
@@ -45,9 +46,9 @@ export const AddSearchEngine = () => {
4546
placeholder="https://google.com?q="
4647
/>
4748
<div>
48-
<button onClick={onAddSearchEngine}>
49-
<TiPlus /> Add
50-
</button>
49+
<Button startIcon={<TiPlus />} size="small" onClick={onAddSearchEngine}>
50+
Add
51+
</Button>
5152
</div>
5253
</div>
5354
{RssInputFeedback && (

src/features/settings/components/GeneralSettings/DNDSettings.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useState } from 'react'
22
import { useNavigate } from 'react-router-dom'
33
import Select, { SingleValue } from 'react-select'
4+
import { Button } from 'src/components/Elements'
45
import { trackDNDEnable } from 'src/lib/analytics'
56
import { useUserPreferences } from 'src/stores/preferences'
67
import { diffBetweenTwoDatesInMinutes } from 'src/utils/DateUtils'
@@ -101,7 +102,9 @@ export const DNDSettings = () => {
101102
/>
102103
</div>
103104

104-
<button onClick={onApplyClicked}>Apply</button>
105+
<Button size="small" onClick={onApplyClicked}>
106+
Apply
107+
</Button>
105108
</div>
106109
{timeoutLabel() && (
107110
<div className="settingHint">

src/features/settings/components/GeneralSettings/GeneralSettings.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react'
22
import Toggle from 'react-toggle'
33
import 'react-toggle/style.css'
4-
import { ChipsSet } from 'src/components/Elements'
4+
import { Button, ChipsSet } from 'src/components/Elements'
55
import { Footer } from 'src/components/Layout'
66
import { SettingsContentLayout } from 'src/components/Layout/SettingsContentLayout'
7+
import { useAuth, User } from 'src/features/auth'
78
import {
89
identifyUserLinksInNewTab,
910
identifyUserListingMode,
@@ -19,6 +20,27 @@ import { Option } from 'src/types'
1920
import { DNDSettings } from './DNDSettings'
2021
import './generalSettings.css'
2122

23+
interface UserInfoProps {
24+
user: User
25+
}
26+
27+
const UserInfo = ({ user }: UserInfoProps) => {
28+
const { logout, providerId } = useAuth()
29+
30+
return (
31+
<div className="userContent">
32+
{user?.imageURL && <img src={user.imageURL} className="userImage"></img>}
33+
<div className="userInfos">
34+
<div className="userName">{user.name}</div>
35+
<div className="providerId">Logged using {providerId}</div>
36+
</div>
37+
<Button onClick={logout} size="small">
38+
Logout
39+
</Button>
40+
</div>
41+
)
42+
}
43+
2244
export const GeneralSettings = () => {
2345
const {
2446
openLinksNewTab,
@@ -62,13 +84,16 @@ export const GeneralSettings = () => {
6284
}
6385
}
6486

87+
const { user } = useAuth()
88+
6589
return (
6690
<SettingsContentLayout
6791
title="General Settings"
6892
description={
6993
'Customize your experience by selecting the number of cards you want to see, the search engine you want to use and more.'
7094
}>
7195
<div>
96+
{user != null && <UserInfo user={user} />}
7297
<div className="settingRow">
7398
<p className="settingTitle">Max number of cards to display</p>
7499
<div className="settingContent">

src/features/settings/components/GeneralSettings/generalSettings.css

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@
3535
.rssButton {
3636
background-color: #ee802f;
3737
color: white;
38+
&:hover {
39+
background-color: #f99147;
40+
color: white;
41+
}
3842
}
39-
.rssButton:hover {
40-
opacity: 0.9;
41-
}
43+
4244
.settingContent {
4345
width: 100%;
4446
flex: 1;
@@ -93,3 +95,32 @@ Select styles
9395
border-radius: 20px !important;
9496
color: var(--tag-secondary-color) !important;
9597
}
98+
99+
.userContent {
100+
width: auto;
101+
padding: 20px 10px;
102+
display: flex;
103+
align-items: center;
104+
border-bottom: 1px solid var(--card-content-divider);
105+
}
106+
.userContent .userImage {
107+
width: 60px;
108+
height: 60px;
109+
border-radius: 100%;
110+
}
111+
.userContent .userInfos {
112+
flex: 1;
113+
width: auto;
114+
margin-left: 10px;
115+
}
116+
.userContent .userName {
117+
font-size: larger;
118+
font-weight: 600;
119+
}
120+
.userContent .userEmail {
121+
font-size: medium;
122+
margin-top: 6px;
123+
}
124+
.userContent .logoutBtn {
125+
margin-left: auto;
126+
}

0 commit comments

Comments
 (0)