Added user change validation and read status
This might be better to just refetch the data with anonymous authorizations
This commit is contained in:
@@ -46,15 +46,14 @@ onMounted(() => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="h-full w-full relative">
|
<div class="h-full w-full relative">
|
||||||
{{ isReadOnly }}
|
|
||||||
<div class="h-full grid grid-rows-[auto,1fr]">
|
<div class="h-full grid grid-rows-[auto,1fr]">
|
||||||
<CalendarMenu />
|
<CalendarMenu />
|
||||||
|
|
||||||
<component :is="currentViewComponent" />
|
<component :is="currentViewComponent" />
|
||||||
|
|
||||||
<CalendarSearch />
|
<CalendarSearch />
|
||||||
<CalendarDialogUpdateEvent />
|
<CalendarDialogUpdateEvent v-if="!isReadOnly" />
|
||||||
<CalendarDialogDeleteEvent />
|
<CalendarDialogDeleteEvent v-if="!isReadOnly" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
} from "@phosphor-icons/vue"
|
} from "@phosphor-icons/vue"
|
||||||
|
|
||||||
const { defaultDate, getFormattedDateTitle, jumpToDate, getRelativeString, revealEditEventModal, revealDeleteEventModal } = useCalendar()
|
const { defaultDate, getFormattedDateTitle, jumpToDate, getRelativeString, revealEditEventModal, revealDeleteEventModal } = useCalendar()
|
||||||
const { lastActiveEvent } = storeToRefs(useCalendar())
|
const { lastActiveEvent, isReadOnly } = storeToRefs(useCalendar())
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
event: CalendarEvent
|
event: CalendarEvent
|
||||||
@@ -151,7 +151,7 @@ function deployDeleteModal() {
|
|||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<menu class="absolute top-4 right-4" :class="cn({ 'top-6': event.hidden })">
|
<menu v-if="!isReadOnly" class="absolute top-4 right-4" :class="cn({ 'top-6': event.hidden })">
|
||||||
<UiPopover v-model:open="commandMenuOpened">
|
<UiPopover v-model:open="commandMenuOpened">
|
||||||
<UiPopoverTrigger as-child>
|
<UiPopoverTrigger as-child>
|
||||||
<UiButton size="icon" variant="outline" class="mix-blend-luminosity bg-gray-300 hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-600">
|
<UiButton size="icon" variant="outline" class="mix-blend-luminosity bg-gray-300 hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-600">
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ import { useCalendar } from "@/stores/CalendarStore"
|
|||||||
import { PhMagnifyingGlass } from "@phosphor-icons/vue"
|
import { PhMagnifyingGlass } from "@phosphor-icons/vue"
|
||||||
|
|
||||||
const { revealAdvancedSearch } = useCalendar()
|
const { revealAdvancedSearch } = useCalendar()
|
||||||
|
const { isReadOnly } = storeToRefs(useCalendar())
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<header class="pt-4 border-slate-400 dark:border-slate-700 border-b-[1px]">
|
<header class="pt-4 border-slate-400 dark:border-slate-700 border-b-[1px]">
|
||||||
<div class="px-6 flex justify-between">
|
<div class="px-6 flex justify-between">
|
||||||
<menu class="flex items-center gap-2">
|
<menu class="flex items-center gap-2">
|
||||||
<li>
|
<li v-if="!isReadOnly">
|
||||||
<CalendarDialogQuickCreateEvent />
|
<CalendarDialogQuickCreateEvent />
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|||||||
@@ -11,11 +11,6 @@ const { data: catData, pending: catPending } = await useLazyFetch("/api/calendar
|
|||||||
|
|
||||||
const cal = computed<Calendar>(() => calendarData?.value?.data as Calendar)
|
const cal = computed<Calendar>(() => calendarData?.value?.data as Calendar)
|
||||||
const categories = computed<Category[]>(() => catData?.value?.data as Category[])
|
const categories = computed<Category[]>(() => catData?.value?.data as Category[])
|
||||||
|
|
||||||
const user = useSupabaseUser()
|
|
||||||
|
|
||||||
const { setReadStatus } = useCalendar()
|
|
||||||
setReadStatus(user.value, cal.value)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -23,9 +23,6 @@ const { data: catData, pending: catPending } = await useLazyFetch("/api/calendar
|
|||||||
|
|
||||||
const cal = computed<Calendar>(() => calendarData?.value?.data as Calendar)
|
const cal = computed<Calendar>(() => calendarData?.value?.data as Calendar)
|
||||||
const categories = computed<Category[]>(() => catData?.value?.data as Category[])
|
const categories = computed<Category[]>(() => catData?.value?.data as Category[])
|
||||||
|
|
||||||
const { setReadStatus } = useCalendar()
|
|
||||||
setReadStatus(user.value, cal.value)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ type DateDirectionTranslationKeys = {
|
|||||||
|
|
||||||
export const useCalendar = defineStore("calendar", () => {
|
export const useCalendar = defineStore("calendar", () => {
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const user = useSupabaseUser()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static calendar config
|
* Static calendar config
|
||||||
@@ -45,14 +46,22 @@ export const useCalendar = defineStore("calendar", () => {
|
|||||||
"year"
|
"year"
|
||||||
])
|
])
|
||||||
|
|
||||||
const activeCalendar = ref<{ id: number; name: string; today: RPGDate } | null>(null)
|
const activeCalendar = ref<{ id: number; name: string; today: RPGDate, gmId: string | undefined } | null>(null)
|
||||||
|
|
||||||
const isReadOnly = ref<boolean>(true)
|
const isReadOnly = ref<boolean>(true)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
function setReadStatus(user: any, calendar: Calendar) {
|
function setReadStatus(gmId: string) {
|
||||||
isReadOnly.value = (!user) || (calendar.world?.gmId !== user?.id)
|
// If the user is not logged in, or the calendar is not owned by the user, it's read-only
|
||||||
|
isReadOnly.value = (!user) || (gmId !== user.value?.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Watch for user changes
|
||||||
|
watch(user, () => {
|
||||||
|
if (activeCalendar.value) {
|
||||||
|
setReadStatus(activeCalendar.value.gmId!)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Month list (queried from API)
|
* Month list (queried from API)
|
||||||
*/
|
*/
|
||||||
@@ -66,10 +75,14 @@ export const useCalendar = defineStore("calendar", () => {
|
|||||||
id: calendarData.id,
|
id: calendarData.id,
|
||||||
name: calendarData.name,
|
name: calendarData.name,
|
||||||
today: calendarData.today,
|
today: calendarData.today,
|
||||||
|
gmId: calendarData.world?.gmId
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefaultDate(activeCalendar.value.today)
|
setDefaultDate(activeCalendar.value.today)
|
||||||
selectDate(activeCalendar.value.today)
|
selectDate(activeCalendar.value.today)
|
||||||
|
if (calendarData.world) {
|
||||||
|
setReadStatus(activeCalendar.value.gmId!)
|
||||||
|
}
|
||||||
|
|
||||||
if (!params.day) {
|
if (!params.day) {
|
||||||
params.day = defaultDate.value.day.toString()
|
params.day = defaultDate.value.day.toString()
|
||||||
|
|||||||
Reference in New Issue
Block a user