feat: rename accounts to user
This commit is contained in:
parent
8dc1fb6493
commit
ed5b8091d3
|
@ -1,12 +1,12 @@
|
|||
<script setup lang="ts">
|
||||
import { isAccountSwitcherOpen, isSigninDialogOpen } from '~/composables/dialog'
|
||||
import { isSigninDialogOpen, isUserSwitcherOpen } from '~/composables/dialog'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ModalDrawer v-model="isAccountSwitcherOpen">
|
||||
<AccountSwitcher />
|
||||
<ModalDrawer v-model="isUserSwitcherOpen">
|
||||
<UserSwitcher />
|
||||
</ModalDrawer>
|
||||
<ModalDialog v-model="isSigninDialogOpen">
|
||||
<AccountSignIn m6 />
|
||||
<UserSignIn m6 />
|
||||
</ModalDialog>
|
||||
</template>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<script setup lang="ts">
|
||||
const allAccounts = useAccounts()
|
||||
const all = useUsers()
|
||||
|
||||
const sortedAccounts = computed(() => {
|
||||
const sorted = computed(() => {
|
||||
return [
|
||||
currentUser.value!,
|
||||
...allAccounts.value.filter(account => account.token !== currentUser.value?.token),
|
||||
...all.value.filter(account => account.token !== currentUser.value?.token),
|
||||
].filter(Boolean)
|
||||
})
|
||||
</script>
|
||||
|
@ -15,16 +15,16 @@ const sortedAccounts = computed(() => {
|
|||
Switch Account
|
||||
</h1>
|
||||
<div mx--2>
|
||||
<template v-for="acc of sortedAccounts" :key="acc.id">
|
||||
<template v-for="user of sorted" :key="user.id">
|
||||
<AccountInfo
|
||||
:account="acc.account"
|
||||
:account="user.account"
|
||||
:link="false"
|
||||
:full-server="true"
|
||||
rounded p2
|
||||
hover:bg-active cursor-pointer
|
||||
@click="loginTo(acc)"
|
||||
@click="loginTo(user)"
|
||||
>
|
||||
<template v-if="acc.token === currentUser?.token">
|
||||
<template v-if="user.token === currentUser?.token">
|
||||
<div flex-auto />
|
||||
<div i-ri:check-line text-primary mya text-2xl />
|
||||
</template>
|
|
@ -1,5 +1,5 @@
|
|||
import { login } from 'masto'
|
||||
import { currentUser } from './accounts'
|
||||
import { currentUser } from './users'
|
||||
import { DEFAULT_SERVER } from '~/constants'
|
||||
|
||||
// TODO: improve upsteam to make this synchronous (delayed auth)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
export const isAccountSwitcherOpen = ref(false)
|
||||
export const isUserSwitcherOpen = ref(false)
|
||||
export const isSigninDialogOpen = ref(false)
|
||||
|
||||
export function openAccountSwitcher() {
|
||||
isAccountSwitcherOpen.value = true
|
||||
export function openUserSwitcher() {
|
||||
isUserSwitcherOpen.value = true
|
||||
}
|
||||
|
||||
export function openSigninDialog() {
|
||||
isSigninDialogOpen.value = true
|
||||
isAccountSwitcherOpen.value = false
|
||||
isUserSwitcherOpen.value = false
|
||||
}
|
||||
|
|
|
@ -2,30 +2,30 @@ import { login as loginMasto } from 'masto'
|
|||
import type { UserLogin } from '~/types'
|
||||
import { DEFAULT_SERVER } from '~/constants'
|
||||
|
||||
const accounts = useLocalStorage<UserLogin[]>('nuxtodon-accounts', [], { deep: true })
|
||||
const currentId = useLocalStorage<string>('nuxtodon-current-user', '')
|
||||
const users = useLocalStorage<UserLogin[]>('nuxtodon-accounts', [], { deep: true })
|
||||
const currentUserId = useLocalStorage<string>('nuxtodon-current-user', '')
|
||||
|
||||
export const currentUser = computed<UserLogin | undefined>(() => {
|
||||
let user: UserLogin | undefined
|
||||
if (currentId.value) {
|
||||
user = accounts.value.find(user => user.account?.id === currentId.value)
|
||||
if (currentUserId.value) {
|
||||
user = users.value.find(user => user.account?.id === currentUserId.value)
|
||||
if (user)
|
||||
return user
|
||||
}
|
||||
// Fallback to the first account
|
||||
return accounts.value[0]
|
||||
return users.value[0]
|
||||
})
|
||||
|
||||
export const currentServer = computed<string>(() => currentUser.value?.server || DEFAULT_SERVER)
|
||||
|
||||
export const useAccounts = () => accounts
|
||||
export const useUsers = () => users
|
||||
|
||||
export async function loginTo(user: UserLogin) {
|
||||
const existing = accounts.value.findIndex(u => u.server === user.server && u.token === user.token)
|
||||
const existing = users.value.findIndex(u => u.server === user.server && u.token === user.token)
|
||||
if (existing !== -1) {
|
||||
if (currentId.value === accounts.value[existing].account?.id)
|
||||
if (currentUserId.value === users.value[existing].account?.id)
|
||||
return null
|
||||
currentId.value = user.account?.id
|
||||
currentUserId.value = user.account?.id
|
||||
await reloadPage()
|
||||
return true
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ export async function loginTo(user: UserLogin) {
|
|||
const me = await masto.accounts.verifyCredentials()
|
||||
user.account = me
|
||||
|
||||
accounts.value.push(user)
|
||||
currentId.value = me.id
|
||||
users.value.push(user)
|
||||
currentUserId.value = me.id
|
||||
await reloadPage()
|
||||
return true
|
||||
}
|
||||
|
@ -48,12 +48,12 @@ export async function signout() {
|
|||
if (!currentUser.value)
|
||||
return
|
||||
|
||||
const index = accounts.value.findIndex(u => u.account?.id === currentUser.value?.account?.id)
|
||||
const index = users.value.findIndex(u => u.account?.id === currentUser.value?.account?.id)
|
||||
if (index === -1)
|
||||
return
|
||||
|
||||
accounts.value.splice(index, 1)
|
||||
currentId.value = accounts.value[0]?.account?.id
|
||||
users.value.splice(index, 1)
|
||||
currentUserId.value = users.value[0]?.account?.id
|
||||
await reloadPage()
|
||||
}
|
||||
|
|
@ -7,14 +7,14 @@
|
|||
<template v-if="currentUser">
|
||||
<PublishWidget px4 draft-key="home" />
|
||||
</template>
|
||||
<AccountSignInEntry v-else />
|
||||
<UserSignInEntry v-else />
|
||||
<div flex-auto />
|
||||
<AccountInfo
|
||||
v-if="currentUser"
|
||||
p4
|
||||
:account="currentUser?.account"
|
||||
:link="false"
|
||||
@click="openAccountSwitcher"
|
||||
@click="openUserSwitcher"
|
||||
/>
|
||||
</slot>
|
||||
</div>
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<script setup lang="ts">
|
||||
const props = defineProps<{
|
||||
modelValue?: boolean
|
||||
}>()
|
||||
|
||||
const params = useRoute().params
|
||||
const user = $computed(() => params.user as string)
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
<script setup lang="ts">
|
||||
definePageMeta({
|
||||
layout: 'none',
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AccountSignIn />
|
||||
</template>
|
Loading…
Reference in a new issue