owltide/plugins/schedule-payload-type.ts

30 lines
692 B
TypeScript
Raw Normal View History

/*
SPDX-FileCopyrightText: © 2025 Hornwitser <code@hornwitser.no>
SPDX-License-Identifier: AGPL-3.0-or-later
*/
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 })
},
);
});