Implement mutable mapping for client entities

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.
This commit is contained in:
Hornwitser 2025-06-23 00:03:37 +02:00
parent 5edea4dd72
commit 6336ccdb96
3 changed files with 467 additions and 0 deletions

View file

@ -0,0 +1,25 @@
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 })
},
);
});