Skip to content

Commit 355c407

Browse files
shleeableYour Name
andauthored
fix #423: invalidate following feed cache on follow/unfollow actions (#428)
* fix: invalidate following feed cache on follow/unfollow actions - Show 'unverified' status for accounts without email verification in admin profiles - Invalidate following-feed Vue Query cache when following/unfollowing users - Updated profile store, video store, search store, and useFollowAccount composable Fixes #423 * Prettier --------- Co-authored-by: Your Name <you@example.com>
1 parent e11410b commit 355c407

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

resources/js/composables/useFollowAccount.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export function useFollowAccount() {
2828
}
2929
})
3030

31+
// Invalidate following feed so it includes new follows
32+
queryClient.invalidateQueries({ queryKey: ['following-feed'] })
3133
// Optionally update user's following count
3234
queryClient.invalidateQueries({ queryKey: ['user-profile'] })
3335
}
@@ -56,6 +58,8 @@ export function useFollowAccount() {
5658
}
5759
})
5860

61+
// Invalidate following feed so it excludes unfollowed accounts
62+
queryClient.invalidateQueries({ queryKey: ['following-feed'] })
5963
// Optionally update user's following count
6064
queryClient.invalidateQueries({ queryKey: ['user-profile'] })
6165
}

resources/js/stores/profile.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { nextTick } from 'vue'
33
import axios from '@/plugins/axios'
44
import { useAuthStore } from '@/stores/auth'
55
import { useAlertModal } from '@/composables/useAlertModal.js'
6+
import { useQueryClient } from '@tanstack/vue-query'
67
const { confirmModal } = useAlertModal()
78

89
export const useProfileStore = defineStore('profile', {
@@ -284,6 +285,11 @@ export const useProfileStore = defineStore('profile', {
284285
this.followerCount = res.follower_count
285286
await nextTick()
286287
await this.getProfileState(this.id)
288+
try {
289+
const queryClient = useQueryClient()
290+
queryClient.invalidateQueries({ queryKey: ['following-feed'] })
291+
} catch (e) {}
292+
287293
if (!prevState && this.isFollowingRequestPending) {
288294
this.pollFollowRequestState().catch((err) => {
289295
console.error('Error polling follow request state:', err)

resources/js/stores/search.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineStore } from 'pinia'
22
import axios from '~/plugins/axios'
33
import { ref } from 'vue'
4+
import { useQueryClient } from '@tanstack/vue-query'
45

56
export const useSearchStore = defineStore('search', () => {
67
const searchQuery = ref('')
@@ -185,6 +186,10 @@ export const useSearchStore = defineStore('search', () => {
185186
user.is_following = true
186187
user.follower_count = (user.follower_count || 0) + 1
187188
}
189+
try {
190+
const queryClient = useQueryClient()
191+
queryClient.invalidateQueries({ queryKey: ['following-feed'] })
192+
} catch (e) {}
188193

189194
return { success: true }
190195
} catch (err) {
@@ -206,6 +211,10 @@ export const useSearchStore = defineStore('search', () => {
206211
user.is_following = false
207212
user.follower_count = Math.max(0, (user.follower_count || 0) - 1)
208213
}
214+
try {
215+
const queryClient = useQueryClient()
216+
queryClient.invalidateQueries({ queryKey: ['following-feed'] })
217+
} catch (e) {}
209218

210219
return { success: true }
211220
} catch (err) {

resources/js/stores/video.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineStore } from 'pinia'
22
import axios from '~/plugins/axios'
3+
import { useQueryClient } from '@tanstack/vue-query'
34

45
export const useVideoStore = defineStore('video', {
56
state: () => ({
@@ -204,6 +205,10 @@ export const useVideoStore = defineStore('video', {
204205
const axiosInstance = axios.getAxiosInstance()
205206
try {
206207
const res = await axiosInstance.post(`/api/v1/account/follow/${userId}`)
208+
try {
209+
const queryClient = useQueryClient()
210+
queryClient.invalidateQueries({ queryKey: ['following-feed'] })
211+
} catch (e) {}
207212
return res.data
208213
} catch (error) {
209214
console.error('Error following user:', error)
@@ -215,6 +220,10 @@ export const useVideoStore = defineStore('video', {
215220
const axiosInstance = axios.getAxiosInstance()
216221
try {
217222
const res = await axiosInstance.post(`/api/v1/account/unfollow/${userId}`)
223+
try {
224+
const queryClient = useQueryClient()
225+
queryClient.invalidateQueries({ queryKey: ['following-feed'] })
226+
} catch (e) {}
218227
return res.data
219228
} catch (error) {
220229
console.error('Error unfollowing user:', error)

0 commit comments

Comments
 (0)