Create a simple Map like class for storing and keeping track of client entities that are synced from the server and have local editable state. This will form the basis for storing entities on the client and should replace the immutable concept used be the ClientSchedule class.
25 lines
558 B
TypeScript
25 lines
558 B
TypeScript
import { Info } from "~/shared/utils/luxon";
|
|
|
|
export default definePayloadPlugin(() => {
|
|
definePayloadReducer(
|
|
"ClientMap",
|
|
data => {
|
|
if (!(data instanceof ClientMap)) {
|
|
return;
|
|
}
|
|
const accountStore = useAccountStore();
|
|
return {
|
|
timezone: accountStore.activeTimezone,
|
|
locale: accountStore.activeLocale,
|
|
api: data.toApi(false),
|
|
};
|
|
},
|
|
);
|
|
definePayloadReviver(
|
|
"ClientMap",
|
|
({ timezone, locale, api }) => {
|
|
const zone = Info.normalizeZone(timezone);
|
|
return ClientMap.fromApi(api, { zone, locale })
|
|
},
|
|
);
|
|
});
|