mirror of
https://github.com/ngthanhvu/kr-phim.git
synced 2026-08-10 14:27:47 +00:00
feat: implement cache busting mechanism and UI improvements
- Added `useCacheBust` composable to manage cache invalidation after movie edits in the admin panel. - Integrated cache busting in movie sync and delete actions to ensure data consistency across pages. - Enhanced UI components in the admin movie management and member management pages for better readability and usability. - Introduced a suggestions tab in the movie detail page to recommend similar movies based on categories. - Updated styles for various elements to improve the overall aesthetic and user experience.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// Composable để invalidate cached data sau khi edit phim ở admin
|
||||
const BUST_KEY = 'cinek-cache-version'
|
||||
|
||||
function getCacheVersion(): number {
|
||||
if (!import.meta.client) return 0
|
||||
return Number(localStorage.getItem(BUST_KEY)) || 0
|
||||
}
|
||||
|
||||
let currentVersion = getCacheVersion()
|
||||
|
||||
// Tăng version mỗi lần gọi — dùng để invalidate useFetch cache
|
||||
export function useCacheBust() {
|
||||
const version = ref(currentVersion)
|
||||
|
||||
function bust() {
|
||||
if (!import.meta.client) return
|
||||
currentVersion++
|
||||
localStorage.setItem(BUST_KEY, String(currentVersion))
|
||||
version.value = currentVersion
|
||||
// Dispatch event để các component khác biết cần refresh
|
||||
window.dispatchEvent(new CustomEvent('cinek:cache-bust', { detail: { version: currentVersion } }))
|
||||
}
|
||||
|
||||
return { version, bust }
|
||||
}
|
||||
|
||||
// Auto-refresh khi có cache bust từ phía admin
|
||||
export function useAutoRefresh(onDataUpdated?: () => void) {
|
||||
const { version } = useCacheBust()
|
||||
|
||||
watch(version, () => {
|
||||
onDataUpdated?.()
|
||||
if (import.meta.client) {
|
||||
window.dispatchEvent(new CustomEvent('cinek:data-updated'))
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user