chad/client/app/composables/use-global-state.ts
Никита Круглицкий ea55b99116
Some checks failed
Deploy / deploy (push) Failing after 7s
#4
2025-10-07 05:39:40 +06:00

31 lines
680 B
TypeScript

import type { ChadClient } from '#shared/types'
import { createGlobalState, useLocalStorage } from '@vueuse/core'
export const useGlobalState = createGlobalState(() => {
const username = useLocalStorage<string>('username', '')
const clients = ref<ChadClient[]>([])
const me = computed(() => clients.value.find(client => client.isMe))
const clientByIdMap = computed(() => {
return clients.value.reduce<Record<ChadClient['id'], ChadClient>>((result, client) => {
result[client.id] = client
return result
}, {})
})
function reset() {
clients.value = []
}
return {
username,
me,
clients,
clientByIdMap,
reset,
}
})