Skip to content

Commit

Permalink
feat: invalidated reaction-info cache on login
Browse files Browse the repository at this point in the history
  • Loading branch information
warmachine028 committed Dec 10, 2024
1 parent 8012424 commit 9d0d4ce
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions client/src/components/AccountMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import { UserAvatar } from '.'
import { useStore } from '@/store'

const AccountMenuItems = ({ handleClose, handleClick, open }) => {
const { user, sign } = useUser()
const { user, } = useUser()
const { signOut } = useAuth()
const { openSnackbar } = useStore()

const logOut = () => {
try {
signOut()
openSnackbar('Logged in successfully')
openSnackbar('Logged out successfully')
} catch (error) {
openSnackbar(error.message, 'error')
}
Expand Down
5 changes: 5 additions & 0 deletions client/src/components/OAuthButtons.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useSignIn } from '@clerk/clerk-react'
import { GitHub, Google } from '@mui/icons-material'
import { Box, Button, ButtonGroup, FormHelperText } from '@mui/material'
import { useQueryClient } from '@tanstack/react-query'
import { useState } from 'react'

const OAuthButtons = () => {
const [error, setError] = useState('')
const { isLoaded, signIn } = useSignIn()
const queryClient = useQueryClient()

const handleOAuthSignIn = async (strategy) => {
if (!isLoaded) {
Expand All @@ -17,6 +19,9 @@ const OAuthButtons = () => {
redirectUrl: '/callback',
redirectUrlComplete: '/'
})
await queryClient.invalidateQueries({
queryKey: ['reaction-info']
})
} catch (err) {
setError(
err.errors[0].longMessage ||
Expand Down
5 changes: 5 additions & 0 deletions client/src/pages/LogIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import { useSignIn } from '@clerk/clerk-react'
import { OAuthButtons } from '@/components'
import { useState } from 'react'
import { useStore } from '@/store'
import { useQueryClient } from '@tanstack/react-query'

const Form = () => {
const initialState = { email: '', password: '' }
const { isLoaded, signIn, setActive } = useSignIn()
const [formData, setFormData] = useState(initialState)
const [error, setError] = useState('')
const queryClient = useQueryClient()
const navigate = useNavigate()

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

if (result.status === 'complete') {
await setActive({ session: result.createdSessionId })
await queryClient.invalidateQueries({
queryKey: ['reaction-info']
})
openSnackbar('Logged in successfully')
navigate('/')
} else {
Expand Down
13 changes: 10 additions & 3 deletions client/src/pages/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,18 @@ const PostCard = ({ post, isLoading, error }) => {
<Typography variant="h4" gutterBottom fontWeight="bold">
{post.title}
</Typography>
<Box mb={2}>
<Stack direction="row" flexWrap="wrap" mb={2} gap={1}>
{post.tags.map((tag) => (
<Chip key={tag} label={tag} sx={{ mr: 1 }} />
<Chip
key={tag}
label={tag}
component={Link}
to={`/hashtag/${tag}`}
onClick={(e) => e.stopPropagation()}
sx={{ textDecoration: 'none' }}
/>
))}
</Box>
</Stack>
<Typography variant="body1" component="p" whiteSpace="pre-line">
{post.description}
</Typography>
Expand Down
5 changes: 5 additions & 0 deletions client/src/pages/VerifyEmail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import { MailOutlined } from '@mui/icons-material'
import { useSignUp } from '@clerk/clerk-react'
import { useNavigate } from 'react-router'
import { useState } from 'react'
import { useQueryClient } from '@tanstack/react-query'

const Form = () => {
const { isLoaded, signUp, setActive } = useSignUp()
const [code, setCode] = useState('')
const [error, setError] = useState('')
const queryClient = useQueryClient()
const navigate = useNavigate()

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

if (result.status === 'complete') {
await setActive({ session: result.createdSessionId })
await queryClient.invalidateQueries({
queryKey: ['reaction-info']
})
navigate('/')
} else {
console.error(JSON.stringify(result, null, 2))
Expand Down

0 comments on commit 9d0d4ce

Please sign in to comment.