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:
parent
5edea4dd72
commit
6336ccdb96
3 changed files with 467 additions and 0 deletions
25
plugins/payload-client-map.ts
Normal file
25
plugins/payload-client-map.ts
Normal 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 })
|
||||
},
|
||||
);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue