feat: basic mutli-accounts support

This commit is contained in:
Anthony Fu 2022-11-23 11:48:01 +08:00
parent 24c573ccf0
commit 241b28241c
15 changed files with 170 additions and 34 deletions

View file

@ -18,7 +18,9 @@ export const currentUser = computed<UserLogin | undefined>(() => {
export const currentServer = computed<string>(() => currentUser.value?.server || DEFAULT_SERVER)
export async function loginCallback(user: UserLogin) {
export const useAccounts = () => accounts
export async function loginTo(user: UserLogin) {
const existing = accounts.value.findIndex(u => u.server === user.server && u.token === user.token)
if (existing !== -1) {
if (currentId.value === accounts.value[existing].account?.id)

View file

@ -8,9 +8,6 @@ import { RouterLink } from 'vue-router'
type Node = DefaultTreeAdapterMap['childNode']
type Element = DefaultTreeAdapterMap['element']
const UserLinkRE = /^https?:\/\/([^/]+)\/@([^/]+)$/
const TagLinkRE = /^https?:\/\/([^/]+)\/tags\/([^/]+)$/
export function defaultHandle(el: Element) {
// Redirect mentions to the user page
if (el.tagName === 'a' && el.attrs.find(i => i.name === 'class' && i.value.includes('mention'))) {

11
composables/dialog.ts Normal file
View file

@ -0,0 +1,11 @@
export const isAccountSwitcherOpen = ref(false)
export const isSigninDialogOpen = ref(false)
export function openAccountSwitcher() {
isAccountSwitcherOpen.value = true
}
export function openSigninDialog() {
isSigninDialogOpen.value = true
isAccountSwitcherOpen.value = false
}

View file

@ -1,5 +1,8 @@
import type { Emoji } from 'masto'
export const UserLinkRE = /^https?:\/\/([^/]+)\/@([^/]+)$/
export const TagLinkRE = /^https?:\/\/([^/]+)\/tags\/([^/]+)$/
export function getDataUrlFromArr(arr: Uint8ClampedArray, w: number, h: number) {
if (typeof w === 'undefined' || typeof h === 'undefined')
w = h = Math.sqrt(arr.length / 4)