diff --git a/nuxt.config.ts b/nuxt.config.ts index 5b7cb0b..e1e80fc 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -1,6 +1,7 @@ // https://nuxt.com/docs/api/configuration/nuxt-config const enableDevtools = !process.env.DISABLE_DEV_TOOLS export default defineNuxtConfig({ + experimental: { renderJsonPayloads: true }, compatibilityDate: '2024-11-01', devtools: { enabled: enableDevtools }, runtimeConfig: { diff --git a/plugins/schedule-payload-type.ts b/plugins/schedule-payload-type.ts new file mode 100644 index 0000000..d1c1a4d --- /dev/null +++ b/plugins/schedule-payload-type.ts @@ -0,0 +1,25 @@ +import { Info } from "~/shared/utils/luxon"; + +export default definePayloadPlugin(() => { + definePayloadReducer( + "ClientSchedule", + data => { + if (!(data instanceof ClientSchedule)) { + return; + } + const accountStore = useAccountStore(); + return { + timezone: accountStore.activeTimezone, + locale: accountStore.activeLocale, + api: data.toApi(false) + }; + }, + ); + definePayloadReviver( + "ClientSchedule", + ({ timezone, locale, api }) => { + const zone = Info.normalizeZone(timezone); + return ClientSchedule.fromApi(api, { zone, locale }) + }, + ); +}); diff --git a/shared/utils/luxon.ts b/shared/utils/luxon.ts index 9575df4..2c18696 100644 --- a/shared/utils/luxon.ts +++ b/shared/utils/luxon.ts @@ -1,5 +1,5 @@ // Wrapper around Luxon to make sure the throwOnInvalid option is set -import { Settings, DateTime, FixedOffsetZone, Zone } from "luxon"; +import { DateTime, FixedOffsetZone, Info, Settings, Zone } from "luxon"; Settings.throwOnInvalid = true; declare module 'luxon' { @@ -8,4 +8,4 @@ declare module 'luxon' { } } -export { DateTime, FixedOffsetZone, Zone } +export { DateTime, FixedOffsetZone, Info, Zone }