Refactor user storage and update
Rename accounts to users to be consistent with the new naming scheme where account only referes to the logged in user of the session and implement live updates of users via a user store which listens for updates from the event stream.
This commit is contained in:
parent
6336ccdb96
commit
3be7f8be05
24 changed files with 331 additions and 182 deletions
|
@ -24,18 +24,18 @@
|
|||
defineProps<{
|
||||
edit?: boolean
|
||||
}>();
|
||||
const { data: accounts } = useAccounts();
|
||||
const accountsById = computed(() => new Map(accounts.value?.map?.(a => [a.id, a])));
|
||||
const usersStore = useUsersStore();
|
||||
await usersStore.fetch();
|
||||
const assignedIds = defineModel<Set<number>>({ required: true });
|
||||
const assigned = computed(
|
||||
() => [...assignedIds.value].map(
|
||||
id => accountsById.value.get(id) ?? { id, name: String(id) }
|
||||
id => usersStore.users.get(id) ?? { id, name: String(id) }
|
||||
)
|
||||
);
|
||||
const crewByName = computed(() => new Map(
|
||||
accounts.value
|
||||
?.filter?.(a => a.type === "crew" || a.type === "admin")
|
||||
?.map?.(a => [a.name, a])
|
||||
[...usersStore.users.values()]
|
||||
.filter(a => a.type === "crew" || a.type === "admin")
|
||||
.map(a => [a.name!, a])
|
||||
));
|
||||
const addName = ref("");
|
||||
function addCrew() {
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
</template>
|
||||
<p v-if="slot.assigned">
|
||||
Crew:
|
||||
{{ [...slot.assigned].map(id => idToAccount.get(id)?.name).join(", ") }}
|
||||
{{ [...slot.assigned].map(id => usersStore.users.get(id)?.name).join(", ") }}
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -48,8 +48,8 @@ defineProps<{
|
|||
}>()
|
||||
|
||||
const accountStore = useAccountStore();
|
||||
const { data: accounts } = await useAccounts();
|
||||
const idToAccount = computed(() => new Map(accounts.value?.map(a => [a.id, a])));
|
||||
const usersStore = useUsersStore();
|
||||
await usersStore.fetch();
|
||||
|
||||
function formatTime(time: DateTime) {
|
||||
return time.toFormat("yyyy-LL-dd HH:mm");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue