Skip to content

Commit 9d0d4ce

Browse files
committed
feat: invalidated reaction-info cache on login
1 parent 8012424 commit 9d0d4ce

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

client/src/components/AccountMenu.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import { UserAvatar } from '.'
2323
import { useStore } from '@/store'
2424

2525
const AccountMenuItems = ({ handleClose, handleClick, open }) => {
26-
const { user, sign } = useUser()
26+
const { user, } = useUser()
2727
const { signOut } = useAuth()
2828
const { openSnackbar } = useStore()
2929

3030
const logOut = () => {
3131
try {
3232
signOut()
33-
openSnackbar('Logged in successfully')
33+
openSnackbar('Logged out successfully')
3434
} catch (error) {
3535
openSnackbar(error.message, 'error')
3636
}

client/src/components/OAuthButtons.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { useSignIn } from '@clerk/clerk-react'
22
import { GitHub, Google } from '@mui/icons-material'
33
import { Box, Button, ButtonGroup, FormHelperText } from '@mui/material'
4+
import { useQueryClient } from '@tanstack/react-query'
45
import { useState } from 'react'
56

67
const OAuthButtons = () => {
78
const [error, setError] = useState('')
89
const { isLoaded, signIn } = useSignIn()
10+
const queryClient = useQueryClient()
911

1012
const handleOAuthSignIn = async (strategy) => {
1113
if (!isLoaded) {
@@ -17,6 +19,9 @@ const OAuthButtons = () => {
1719
redirectUrl: '/callback',
1820
redirectUrlComplete: '/'
1921
})
22+
await queryClient.invalidateQueries({
23+
queryKey: ['reaction-info']
24+
})
2025
} catch (err) {
2126
setError(
2227
err.errors[0].longMessage ||

client/src/pages/LogIn.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ import { useSignIn } from '@clerk/clerk-react'
1616
import { OAuthButtons } from '@/components'
1717
import { useState } from 'react'
1818
import { useStore } from '@/store'
19+
import { useQueryClient } from '@tanstack/react-query'
1920

2021
const Form = () => {
2122
const initialState = { email: '', password: '' }
2223
const { isLoaded, signIn, setActive } = useSignIn()
2324
const [formData, setFormData] = useState(initialState)
2425
const [error, setError] = useState('')
26+
const queryClient = useQueryClient()
2527
const navigate = useNavigate()
2628

2729
const handleChange = (e) =>
@@ -41,6 +43,9 @@ const Form = () => {
4143

4244
if (result.status === 'complete') {
4345
await setActive({ session: result.createdSessionId })
46+
await queryClient.invalidateQueries({
47+
queryKey: ['reaction-info']
48+
})
4449
openSnackbar('Logged in successfully')
4550
navigate('/')
4651
} else {

client/src/pages/Post.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,18 @@ const PostCard = ({ post, isLoading, error }) => {
8080
<Typography variant="h4" gutterBottom fontWeight="bold">
8181
{post.title}
8282
</Typography>
83-
<Box mb={2}>
83+
<Stack direction="row" flexWrap="wrap" mb={2} gap={1}>
8484
{post.tags.map((tag) => (
85-
<Chip key={tag} label={tag} sx={{ mr: 1 }} />
85+
<Chip
86+
key={tag}
87+
label={tag}
88+
component={Link}
89+
to={`/hashtag/${tag}`}
90+
onClick={(e) => e.stopPropagation()}
91+
sx={{ textDecoration: 'none' }}
92+
/>
8693
))}
87-
</Box>
94+
</Stack>
8895
<Typography variant="body1" component="p" whiteSpace="pre-line">
8996
{post.description}
9097
</Typography>

client/src/pages/VerifyEmail.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import { MailOutlined } from '@mui/icons-material'
1313
import { useSignUp } from '@clerk/clerk-react'
1414
import { useNavigate } from 'react-router'
1515
import { useState } from 'react'
16+
import { useQueryClient } from '@tanstack/react-query'
1617

1718
const Form = () => {
1819
const { isLoaded, signUp, setActive } = useSignUp()
1920
const [code, setCode] = useState('')
2021
const [error, setError] = useState('')
22+
const queryClient = useQueryClient()
2123
const navigate = useNavigate()
2224

2325
const handleSubmit = async (event) => {
@@ -33,6 +35,9 @@ const Form = () => {
3335

3436
if (result.status === 'complete') {
3537
await setActive({ session: result.createdSessionId })
38+
await queryClient.invalidateQueries({
39+
queryKey: ['reaction-info']
40+
})
3641
navigate('/')
3742
} else {
3843
console.error(JSON.stringify(result, null, 2))

0 commit comments

Comments
 (0)