From fa44fae99185777b0f031a6d9c91c9aefe80723e Mon Sep 17 00:00:00 2001
From: Daniel Roe
Date: Sun, 29 Jan 2023 07:52:01 -0800
Subject: [PATCH 1/9] perf!: allow tree-shaking unstorage drivers (#1516)
* perf: allow tree-shaking unstorage drivers
* fix: allow overriding fsBase at runtime
* fix: remove `fsBase` export
---
modules/tauri/index.ts | 1 +
modules/tauri/runtime/storage-config.ts | 2 ++
nuxt.config.ts | 17 ++++++++++++++---
server/shared.ts | 12 +++++++-----
4 files changed, 24 insertions(+), 8 deletions(-)
create mode 100644 modules/tauri/runtime/storage-config.ts
diff --git a/modules/tauri/index.ts b/modules/tauri/index.ts
index 5c0fec95..9d445922 100644
--- a/modules/tauri/index.ts
+++ b/modules/tauri/index.ts
@@ -22,6 +22,7 @@ export default defineNuxtModule({
...nuxt.options.alias,
'unstorage/drivers/fs': 'unenv/runtime/mock/proxy',
'unstorage/drivers/cloudflare-kv-http': 'unenv/runtime/mock/proxy',
+ '#storage-config': resolve('./runtime/storage-config'),
'node:events': 'unenv/runtime/node/events/index',
'#build-info': resolve('./runtime/build-info'),
}
diff --git a/modules/tauri/runtime/storage-config.ts b/modules/tauri/runtime/storage-config.ts
new file mode 100644
index 00000000..2f1ae291
--- /dev/null
+++ b/modules/tauri/runtime/storage-config.ts
@@ -0,0 +1,2 @@
+export const driver = undefined
+export const fsBase = ''
diff --git a/nuxt.config.ts b/nuxt.config.ts
index e0bd7c8d..266601be 100644
--- a/nuxt.config.ts
+++ b/nuxt.config.ts
@@ -1,4 +1,4 @@
-import { createResolver } from '@nuxt/kit'
+import { createResolver, useNuxt } from '@nuxt/kit'
import Inspect from 'vite-plugin-inspect'
import { isCI, isDevelopment, isWindows } from 'std-env'
import { isPreview } from './config/env'
@@ -86,6 +86,11 @@ export default defineNuxtConfig({
'postcss-nested': {},
},
},
+ appConfig: {
+ storage: {
+ driver: process.env.NUXT_STORAGE_DRIVER ?? (isCI ? 'cloudflare' : 'fs'),
+ },
+ },
runtimeConfig: {
adminKey: '',
cloudflare: {
@@ -102,8 +107,7 @@ export default defineNuxtConfig({
defaultServer: 'm.webtoo.ls',
},
storage: {
- driver: isCI ? 'cloudflare' : 'fs',
- fsBase: 'node_modules/.cache/servers',
+ fsBase: 'node_modules/.cache/app',
},
},
routeRules: {
@@ -126,6 +130,13 @@ export default defineNuxtConfig({
ignore: ['/settings'],
},
},
+ hooks: {
+ 'nitro:config': function (config) {
+ const nuxt = useNuxt()
+ config.virtual = config.virtual || {}
+ config.virtual['#storage-config'] = `export const driver = ${JSON.stringify(nuxt.options.appConfig.storage.driver)}`
+ },
+ },
app: {
keepalive: true,
head: {
diff --git a/server/shared.ts b/server/shared.ts
index 37f4b2bd..5a0d97e5 100644
--- a/server/shared.ts
+++ b/server/shared.ts
@@ -14,29 +14,31 @@ import cached from './cache-driver'
// @ts-expect-error virtual import
import { env } from '#build-info'
+// @ts-expect-error virtual import
+import { driver } from '#storage-config'
import type { AppInfo } from '~/types'
import { APP_NAME } from '~/constants'
-const config = useRuntimeConfig()
-
const fs = _fs as typeof import('unstorage/dist/drivers/fs')['default']
const kv = _kv as typeof import('unstorage/dist/drivers/cloudflare-kv-http')['default']
const memory = _memory as typeof import('unstorage/dist/drivers/memory')['default']
const storage = useStorage() as Storage
-if (config.storage.driver === 'fs') {
+if (driver === 'fs') {
+ const config = useRuntimeConfig()
storage.mount('servers', fs({ base: config.storage.fsBase }))
}
-else if (config.storage.driver === 'cloudflare') {
+else if (driver === 'cloudflare') {
+ const config = useRuntimeConfig()
storage.mount('servers', cached(kv({
accountId: config.cloudflare.accountId,
namespaceId: config.cloudflare.namespaceId,
apiToken: config.cloudflare.apiToken,
})))
}
-else if (config.storage.driver === 'memory') {
+else if (driver === 'memory') {
storage.mount('servers', memory())
}
From 72bf6fb6f0e81f0509b7be39e15255aeccf367b2 Mon Sep 17 00:00:00 2001
From: Stanislas
Date: Sun, 29 Jan 2023 16:58:32 +0100
Subject: [PATCH 2/9] fix: handle account switching when accounts have the same
id (#1510)
---
components/user/UserPicker.vue | 4 ++--
composables/users.ts | 35 ++++++++++++++--------------------
constants/index.ts | 1 -
3 files changed, 16 insertions(+), 24 deletions(-)
diff --git a/components/user/UserPicker.vue b/components/user/UserPicker.vue
index 23ea40ae..f3c3d486 100644
--- a/components/user/UserPicker.vue
+++ b/components/user/UserPicker.vue
@@ -5,7 +5,7 @@ const all = useUsers()
const router = useRouter()
const clickUser = (user: UserLogin) => {
- if (user.account.id === currentUser.value?.account.id)
+ if (user.account.acct === currentUser.value?.account.acct)
router.push(getAccountRoute(user.account))
else
switchUser(user)
@@ -21,7 +21,7 @@ const clickUser = (user: UserLogin) => {
flex rounded
cursor-pointer
aria-label="Switch user"
- :class="user.account.id === currentUser?.account.id ? '' : 'op25 grayscale'"
+ :class="user.account.acct === currentUser?.account.acct ? '' : 'op25 grayscale'"
hover="filter-none op100"
@click="clickUser(user)"
>
diff --git a/composables/users.ts b/composables/users.ts
index f5925e7a..e0ff87b1 100644
--- a/composables/users.ts
+++ b/composables/users.ts
@@ -7,7 +7,6 @@ import type { UserLogin } from '~/types'
import type { Overwrite } from '~/types/utils'
import {
DEFAULT_POST_CHARS_LIMIT,
- STORAGE_KEY_CURRENT_USER,
STORAGE_KEY_CURRENT_USER_HANDLE,
STORAGE_KEY_NODES,
STORAGE_KEY_NOTIFICATION,
@@ -46,7 +45,7 @@ const initializeUsers = async (): Promise[ | RemovableRef]>(STORAGE_KEY_SERVERS, mock ? mock.server : {}, { deep: true })
export const nodes = useLocalStorage>(STORAGE_KEY_NODES, {}, { deep: true })
-const currentUserId = useLocalStorage(STORAGE_KEY_CURRENT_USER, mock ? mock.user.account.id : '')
+const currentUserHandle = useLocalStorage(STORAGE_KEY_CURRENT_USER_HANDLE, mock ? mock.user.account.id : '')
export type ElkInstance = Partial & {
uri: string
@@ -56,8 +55,8 @@ export type ElkInstance = Partial & {
export const getInstanceCache = (server: string): mastodon.v1.Instance | undefined => instances.value[server]
export const currentUser = computed(() => {
- if (currentUserId.value) {
- const user = users.value.find(user => user.account?.id === currentUserId.value)
+ if (currentUserHandle.value) {
+ const user = users.value.find(user => user.account?.acct === currentUserHandle.value)
if (user)
return user
}
@@ -84,12 +83,12 @@ if (process.client) {
const windowReload = () => {
document.visibilityState === 'visible' && window.location.reload()
}
- watch(currentUserId, async (id, oldId) => {
+ watch(currentUserHandle, async (handle, oldHandle) => {
// when sign in or switch account
- if (id) {
- if (id === currentUser.value?.account?.id) {
+ if (handle) {
+ if (handle === currentUser.value?.account?.acct) {
// when sign in, the other tab will not have the user, idb is not reactive
- const newUser = users.value.find(user => user.account?.id === id)
+ const newUser = users.value.find(user => user.account?.acct === handle)
// if the user is there, then we are switching account
if (newUser) {
// check if the change is on current tab: if so, don't reload
@@ -101,19 +100,13 @@ if (process.client) {
window.addEventListener('visibilitychange', windowReload, { capture: true })
}
// when sign out
- else if (oldId) {
- const oldUser = users.value.find(user => user.account?.id === oldId)
+ else if (oldHandle) {
+ const oldUser = users.value.find(user => user.account?.acct === oldHandle)
// when sign out, the other tab will not have the user, idb is not reactive
if (oldUser)
window.addEventListener('visibilitychange', windowReload, { capture: true })
}
}, { immediate: true, flush: 'post' })
-
- // for injected script to read
- const currentUserHandle = computed(() => currentUser.value?.account.acct || '')
- watchEffect(() => {
- localStorage.setItem(STORAGE_KEY_CURRENT_USER_HANDLE, currentUserHandle.value)
- })
}
export const useUsers = () => users
@@ -144,7 +137,7 @@ export async function loginTo(masto: ElkMasto, user: Overwrite
Date: Sun, 29 Jan 2023 16:20:47 -0800
Subject: [PATCH 3/9] chore(deps): update dependency vitest to ^0.28.3 (#1523)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
---
package.json | 2 +-
pnpm-lock.yaml | 9 ++++-----
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/package.json b/package.json
index 780d5390..1e17a63e 100644
--- a/package.json
+++ b/package.json
@@ -118,7 +118,7 @@
"unplugin-vue-inspector": "^0.0.2",
"vite-plugin-inspect": "^0.7.14",
"vite-plugin-pwa": "^0.14.1",
- "vitest": "^0.28.1",
+ "vitest": "^0.28.3",
"vue-tsc": "^1.0.24",
"workbox-build": "^6.5.4",
"workbox-window": "^6.5.4"
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 40e972d8..dac482df 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -119,7 +119,7 @@ importers:
unplugin-vue-inspector: ^0.0.2
vite-plugin-inspect: ^0.7.14
vite-plugin-pwa: ^0.14.1
- vitest: ^0.28.1
+ vitest: ^0.28.3
vue-advanced-cropper: ^2.8.8
vue-tsc: ^1.0.24
vue-virtual-scroller: 2.0.0-beta.7
@@ -216,7 +216,7 @@ importers:
unplugin-auto-import: 0.13.0_@vueuse+core@9.11.1
unplugin-vue-inspector: 0.0.2
vite-plugin-inspect: 0.7.14
- vite-plugin-pwa: 0.14.1_tz3vz2xt4jvid2diblkpydcyn4
+ vite-plugin-pwa: 0.14.1
vitest: 0.28.3_jsdom@21.1.0
vue-tsc: 1.0.24_typescript@4.9.4
workbox-build: 6.5.4
@@ -12949,12 +12949,10 @@ packages:
- supports-color
dev: true
- /vite-plugin-pwa/0.14.1_tz3vz2xt4jvid2diblkpydcyn4:
+ /vite-plugin-pwa/0.14.1:
resolution: {integrity: sha512-5zx7yhQ8RTLwV71+GA9YsQQ63ALKG8XXIMqRJDdZkR8ZYftFcRgnzM7wOWmQZ/DATspyhPih5wCdcZnAIsM+mA==}
peerDependencies:
vite: ^3.1.0 || ^4.0.0
- workbox-build: ^6.5.4
- workbox-window: ^6.5.4
dependencies:
'@rollup/plugin-replace': 5.0.2_rollup@3.10.1
debug: 4.3.4
@@ -12964,6 +12962,7 @@ packages:
workbox-build: 6.5.4
workbox-window: 6.5.4
transitivePeerDependencies:
+ - '@types/babel__core'
- supports-color
dev: true
From fbdaf8bbef166c894350c67ef112e28fd020c17c Mon Sep 17 00:00:00 2001
From: Anthony Fu
Date: Mon, 30 Jan 2023 10:36:39 +0100
Subject: [PATCH 4/9] chore: cleanup
---
tests/__snapshots__/content-rich.test.ts.snap | 164 ------------------
tests/__snapshots__/html-parse.test.ts.snap | 144 ---------------
tests/nuxt/content-rich.test.ts | 13 +-
3 files changed, 4 insertions(+), 317 deletions(-)
delete mode 100644 tests/__snapshots__/content-rich.test.ts.snap
delete mode 100644 tests/__snapshots__/html-parse.test.ts.snap
diff --git a/tests/__snapshots__/content-rich.test.ts.snap b/tests/__snapshots__/content-rich.test.ts.snap
deleted file mode 100644
index 289bfb73..00000000
--- a/tests/__snapshots__/content-rich.test.ts.snap
+++ /dev/null
@@ -1,164 +0,0 @@
-// Vitest Snapshot v1
-
-exports[`content-rich > block with backticks 1`] = `"
[(\`number string) (\`tag string)]
"`;
-
-exports[`content-rich > block with injected html, with a known language 1`] = `
-"
-
- <a href="javascript:alert(1)">click me</a>
-
-
-"
-`;
-
-exports[`content-rich > block with injected html, with an unknown language 1`] = `
-"
-
- <a href="javascript:alert(1)">click me</a>
-
-
-"
-`;
-
-exports[`content-rich > block with injected html, without language 1`] = `
-"
-
- <a href="javascript:alert(1)">click me</a>
-
-
-"
-`;
-
-exports[`content-rich > code frame 1`] = `
-"Testing code block
import { useMouse, usePreferredDark } from '@vueuse/core'
-// tracks mouse position
-const { x, y } = useMouse()
-// is the user prefers dark theme
-const isDark = usePreferredDark() "
-`;
-
-exports[`content-rich > code frame 2 1`] = `
-"
-
- Testing
-
const a = hello
-
-"
-`;
-
-exports[`content-rich > code frame empty 1`] = `"
"`;
-
-exports[`content-rich > code frame no lang 1`] = `"
hello world no lang"`;
-
-exports[`content-rich > custom emoji 1`] = `
-"Daniel Roe
-
-
-"
-`;
-
-exports[`content-rich > empty 1`] = `""`;
-
-exports[`content-rich > group mention > html 1`] = `
-"
-
-
-"
-`;
-
-exports[`content-rich > handles formatting from servers 1`] = `
-"Fedi HTML Support Survey
-Does the following formatting come through accurately for you?
-
-
- This is an indented bulleted list (not just asterisks).
- This line is bold.
- This line is italic.
-
-
- This list...
- ...is numbered and indented
-
-This line is larger.
-"
-`;
-
-exports[`content-rich > handles html within code blocks 1`] = `
-"
- HTML block code:
-
-<span class="icon--noto icon--noto--1st-place-medal"></span>
-<span class="icon--noto icon--noto--2nd-place-medal-medal"></span>
-
-"
-`;
-
-exports[`content-rich > inline code with link 1`] = `
-"
- Inline code with link:
- https://api.iconify.design/noto.css?icons=1st-place-medal,2nd-place-medal
-
-"
-`;
-
-exports[`content-rich > link + mention 1`] = `
-"
- Happy
-
- weβre now using
-
- (migrated from chai+mocha)
- https:// github.com/ayoayco/astro-react ive-library/pull/203
-
-"
-`;
-
-exports[`content-rich > plain text 1`] = `
-"hello there
-"
-`;
-
-exports[`editor > transform mentions 1`] = `
-"
-@elk Hello"
-`;
diff --git a/tests/__snapshots__/html-parse.test.ts.snap b/tests/__snapshots__/html-parse.test.ts.snap
deleted file mode 100644
index d7f36a0d..00000000
--- a/tests/__snapshots__/html-parse.test.ts.snap
+++ /dev/null
@@ -1,144 +0,0 @@
-// Vitest Snapshot v1
-
-exports[`html-parse > code frame > html 1`] = `
-"Testing code block
import { useMouse, usePreferredDark } from '@vueuse/core'
-// tracks mouse position
-const { x, y } = useMouse()
-// is the user prefers dark theme
-const isDark = usePreferredDark()
"
-`;
-
-exports[`html-parse > code frame > text 1`] = `
-"Testing code block
-
-
-\`\`\`ts
-import { useMouse, usePreferredDark } from '@vueuse/core'
-// tracks mouse position
-const { x, y } = useMouse()
-// is the user prefers dark theme
-const isDark = usePreferredDark()
-\`\`\`"
-`;
-
-exports[`html-parse > code frame 2 > html 1`] = `
-"
- @antfu
- Testing
-
const a = hello
-
-"
-`;
-
-exports[`html-parse > code frame 2 > text 1`] = `
-"@antfu Testing
-
-\`\`\`ts
-const a = hello
-\`\`\`"
-`;
-
-exports[`html-parse > custom emoji > html 1`] = `
-"Daniel Roe
-
-
-"
-`;
-
-exports[`html-parse > custom emoji > text 1`] = `"Daniel Roe :nuxt:"`;
-
-exports[`html-parse > emojis > html 1`] = `
-"
-
-
-"
-`;
-
-exports[`html-parse > emojis > text 1`] = `"π«π· π¨βπ©βπ¦ π©βππ§π½βπ"`;
-
-exports[`html-parse > empty > html 1`] = `""`;
-
-exports[`html-parse > empty > text 1`] = `""`;
-
-exports[`html-parse > html entities > html 1`] = `
-"Hello <World />.
-"
-`;
-
-exports[`html-parse > html entities > text 1`] = `"Hello ."`;
-
-exports[`html-parse > inline markdown > html 1`] = `"text code
bold italic del
code block
"`;
-
-exports[`html-parse > inline markdown > text 1`] = `
-"text \`code\` **bold** *italic* ~~del~~
-
-
-\`\`\`js
-code block
-\`\`\`"
-`;
-
-exports[`html-parse > link + mention > html 1`] = `
-"
- Happy
-
- weβre now using
- @vitest
- (migrated from chai+mocha)
- https:// github.com/ayoayco/astro-react ive-library/pull/203
-
-"
-`;
-
-exports[`html-parse > link + mention > text 1`] = `"Happy π€ weβre now using @vitest (migrated from chai+mocha) https://github.com/ayoayco/astro-reactive-library/pull/203"`;
diff --git a/tests/nuxt/content-rich.test.ts b/tests/nuxt/content-rich.test.ts
index 9d32b592..d21bc30e 100644
--- a/tests/nuxt/content-rich.test.ts
+++ b/tests/nuxt/content-rich.test.ts
@@ -287,15 +287,10 @@ vi.mock('shiki-es', async (importOriginal) => {
}
})
-vi.mock('~/components/content/ContentMentionGroup.vue', async () => {
- const { defineComponent, h } = await import('vue')
- return {
- default: defineComponent({
- setup(props, { slots }) {
- return () => h('mention-group', null, { default: () => slots?.default?.() })
- },
- }),
- }
+mockComponent('ContentMentionGroup', {
+ setup(props, { slots }) {
+ return () => h('mention-group', null, { default: () => slots?.default?.() })
+ },
})
mockComponent('AccountHoverWrapper', {
From 8d792d003ddad681e7b2f680d30a0128561ebd46 Mon Sep 17 00:00:00 2001
From: Anthony Fu
Date: Mon, 30 Jan 2023 11:58:18 +0100
Subject: [PATCH 5/9] refactor: make auto import more explicit
---
components/help/HelpPreview.vue | 2 +-
components/publish/PublishAttachment.vue | 2 +-
components/publish/PublishWidget.vue | 2 +-
components/user/UserSwitcher.vue | 2 +-
composables/about.ts | 2 +-
composables/command.ts | 2 +-
composables/content-render.ts | 2 +-
composables/masto/account.ts | 4 ++--
composables/masto/masto.ts | 2 +-
composables/screen.ts | 2 --
composables/users.ts | 12 ++++++------
pages/settings/about/index.vue | 2 +-
scripts/avatars.ts | 4 ++--
13 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/components/help/HelpPreview.vue b/components/help/HelpPreview.vue
index 90cc4e58..8e37f4f6 100644
--- a/components/help/HelpPreview.vue
+++ b/components/help/HelpPreview.vue
@@ -30,7 +30,7 @@ const emit = defineEmits<{
{{ $t('help.desc_para3') }}
-
+
diff --git a/components/publish/PublishAttachment.vue b/components/publish/PublishAttachment.vue
index fa29a2e7..3e1a29ec 100644
--- a/components/publish/PublishAttachment.vue
+++ b/components/publish/PublishAttachment.vue
@@ -34,7 +34,7 @@ const toggleApply = () => {
text-white px2 py2 rounded-full cursor-pointer
@click="$emit('remove')"
>
-
+
diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue
index 9a055aa8..93eed711 100644
--- a/components/publish/PublishWidget.vue
+++ b/components/publish/PublishWidget.vue
@@ -147,7 +147,7 @@ defineExpose({
>
- {{ acctToShortHandle(m) }}
+ {{ accountToShortHandle(m) }}
diff --git a/components/user/UserSwitcher.vue b/components/user/UserSwitcher.vue
index 21774835..e8a766f1 100644
--- a/components/user/UserSwitcher.vue
+++ b/components/user/UserSwitcher.vue
@@ -51,7 +51,7 @@ const clickUser = (user: UserLogin) => {
:text="$t('user.sign_out_account', [getFullHandle(currentUser.account)])"
icon="i-ri:logout-box-line rtl-flip"
w-full
- @click="signout"
+ @click="signOut"
/>
diff --git a/composables/about.ts b/composables/about.ts
index 89d9df79..d793c76f 100644
--- a/composables/about.ts
+++ b/composables/about.ts
@@ -7,7 +7,7 @@ export interface Team {
mastodon: string
}
-export const teams: Team[] = [
+export const elkTeamMembers: Team[] = [
{
github: 'antfu',
display: 'Anthony Fu',
diff --git a/composables/command.ts b/composables/command.ts
index 6c19171b..da2c5a26 100644
--- a/composables/command.ts
+++ b/composables/command.ts
@@ -349,7 +349,7 @@ export const provideGlobalCommands = () => {
icon: 'i-ri:logout-box-line',
onActivate() {
- signout()
+ signOut()
},
})
}
diff --git a/composables/content-render.ts b/composables/content-render.ts
index 26d35073..3d736f84 100644
--- a/composables/content-render.ts
+++ b/composables/content-render.ts
@@ -21,7 +21,7 @@ export function contentToVNode(
return h(Fragment, (tree.children as Node[] || []).map(n => treeToVNode(n)))
}
-export function nodeToVNode(node: Node): VNode | string | null {
+function nodeToVNode(node: Node): VNode | string | null {
if (node.type === TEXT_NODE)
return node.value
diff --git a/composables/masto/account.ts b/composables/masto/account.ts
index b97c4ba1..a1041ca3 100644
--- a/composables/masto/account.ts
+++ b/composables/masto/account.ts
@@ -7,14 +7,14 @@ export function getDisplayName(account: mastodon.v1.Account, options?: { rich?:
return displayName.replace(/:([\w-]+?):/g, '')
}
-export function acctToShortHandle(acct: string) {
+export function accountToShortHandle(acct: string) {
return `@${acct.includes('@') ? acct.split('@')[0] : acct}`
}
export function getShortHandle({ acct }: mastodon.v1.Account) {
if (!acct)
return ''
- return acctToShortHandle(acct)
+ return accountToShortHandle(acct)
}
export function getServerName(account: mastodon.v1.Account) {
diff --git a/composables/masto/masto.ts b/composables/masto/masto.ts
index c9726830..d64addaa 100644
--- a/composables/masto/masto.ts
+++ b/composables/masto/masto.ts
@@ -47,7 +47,7 @@ export function mastoLogin(masto: ElkMasto, user: Pick | RemovableRef>(STORAGE_KEY_SERVERS, mock ? mock.server : {}, { deep: true })
-export const nodes = useLocalStorage>(STORAGE_KEY_NODES, {}, { deep: true })
+const nodes = useLocalStorage>(STORAGE_KEY_NODES, {}, { deep: true })
const currentUserHandle = useLocalStorage(STORAGE_KEY_CURRENT_USER_HANDLE, mock ? mock.user.account.id : '')
+export const instanceStorage = useLocalStorage>(STORAGE_KEY_SERVERS, mock ? mock.server : {}, { deep: true })
export type ElkInstance = Partial & {
uri: string
/** support GoToSocial */
accountDomain?: string | null
}
-export const getInstanceCache = (server: string): mastodon.v1.Instance | undefined => instances.value[server]
+export const getInstanceCache = (server: string): mastodon.v1.Instance | undefined => instanceStorage.value[server]
export const currentUser = computed(() => {
if (currentUserHandle.value) {
@@ -65,7 +65,7 @@ export const currentUser = computed(() => {
})
const publicInstance = ref(null)
-export const currentInstance = computed(() => currentUser.value ? instances.value[currentUser.value.server] ?? null : publicInstance.value)
+export const currentInstance = computed(() => currentUser.value ? instanceStorage.value[currentUser.value.server] ?? null : publicInstance.value)
export function getInstanceDomain(instance: ElkInstance) {
return instance.accountDomain || withoutProtocol(instance.uri)
@@ -231,7 +231,7 @@ export async function switchUser(user: UserLogin) {
}
}
-export async function signout() {
+export async function signOut() {
// TODO: confirm
if (!currentUser.value)
return
@@ -246,7 +246,7 @@ export async function signout() {
// Clear stale data
clearUserLocalStorage()
if (!users.value.some((u, i) => u.server === currentUser.value!.server && i !== index))
- delete instances.value[currentUser.value.server]
+ delete instanceStorage.value[currentUser.value.server]
await removePushNotifications(currentUser.value)
diff --git a/pages/settings/about/index.vue b/pages/settings/about/index.vue
index 7524d7d2..8a8ade13 100644
--- a/pages/settings/about/index.vue
+++ b/pages/settings/about/index.vue
@@ -115,7 +115,7 @@ const handleShowCommit = () => {
{
+ await Promise.all(elkTeamMembers.reduce((acc, { github }) => {
acc.push(...sizes.map(s => download(`https://github.com/${github}.png?size=${s}`, join(avatarsDir, `${github}-${s}x${s}.png`))))
return acc
}, [] as Promise[]))
From 2a4862fb42e12df15437c13587eee84846576e83 Mon Sep 17 00:00:00 2001
From: Anthony Fu
Date: Mon, 30 Jan 2023 12:09:04 +0100
Subject: [PATCH 6/9] feat(ui): display post language
---
components/publish/PublishLanguagePicker.vue | 14 ++-----------
components/publish/PublishWidget.vue | 22 ++++++++++++--------
composables/langugage.ts | 11 ++++++++++
3 files changed, 26 insertions(+), 21 deletions(-)
create mode 100644 composables/langugage.ts
diff --git a/components/publish/PublishLanguagePicker.vue b/components/publish/PublishLanguagePicker.vue
index bd7f139b..d0532cc7 100644
--- a/components/publish/PublishLanguagePicker.vue
+++ b/components/publish/PublishLanguagePicker.vue
@@ -10,17 +10,7 @@ const { t } = useI18n()
const languageKeyword = $ref('')
-const languageList: {
- code: string
- nativeName: string
- name: string
-}[] = ISO6391.getAllCodes().map(code => ({
- code,
- nativeName: ISO6391.getNativeName(code),
- name: ISO6391.getName(code),
-}))
-
-const fuse = new Fuse(languageList, {
+const fuse = new Fuse(languagesNameList, {
keys: ['code', 'nativeName', 'name'],
shouldSort: true,
})
@@ -28,7 +18,7 @@ const fuse = new Fuse(languageList, {
const languages = $computed(() =>
languageKeyword.trim()
? fuse.search(languageKeyword).map(r => r.item)
- : [...languageList].sort(({ code: a }, { code: b }) => {
+ : [...languagesNameList].sort(({ code: a }, { code: b }) => {
return a === modelValue ? -1 : b === modelValue ? 1 : a.localeCompare(b)
}),
)
diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue
index 93eed711..dfbc0c95 100644
--- a/components/publish/PublishWidget.vue
+++ b/components/publish/PublishWidget.vue
@@ -62,6 +62,7 @@ const { editor } = useTiptap({
},
onPaste: handlePaste,
})
+
const characterCount = $computed(() => {
let length = stringLength(htmlToText(editor.value?.getHTML() || ''))
@@ -76,6 +77,8 @@ const characterCount = $computed(() => {
return length
})
+const postLanguageDisplay = $computed(() => languagesNameList.find(i => i.code === draft.params.language)?.nativeName)
+
async function handlePaste(evt: ClipboardEvent) {
const files = evt.clipboardData?.files
if (!files || files.length === 0)
@@ -278,17 +281,11 @@ defineExpose({
{{ characterCount ?? 0 }}/ {{ characterLimit }}
-
-
-
-
-
-
-
-
-
+
+ {{ postLanguageDisplay }}
+
@@ -298,6 +295,13 @@ defineExpose({
+
+
+
+
+
+
+
diff --git a/composables/langugage.ts b/composables/langugage.ts
new file mode 100644
index 00000000..2584afc8
--- /dev/null
+++ b/composables/langugage.ts
@@ -0,0 +1,11 @@
+import ISO6391 from 'iso-639-1'
+
+export const languagesNameList: {
+ code: string
+ nativeName: string
+ name: string
+}[] = ISO6391.getAllCodes().map(code => ({
+ code,
+ nativeName: ISO6391.getNativeName(code),
+ name: ISO6391.getName(code),
+}))
From e277832b61783a84e9d4c0fd94c321b0a38d01f5 Mon Sep 17 00:00:00 2001
From: Anthony Fu
Date: Mon, 30 Jan 2023 12:20:22 +0100
Subject: [PATCH 7/9] fix: avoid reference context in `getDefaultDraft`
---
components/publish/PublishLanguagePicker.vue | 17 ++++++++--------
components/publish/PublishWidget.vue | 6 +++---
composables/masto/publish.ts | 21 +++++++++++++-------
composables/masto/statusDrafts.ts | 12 +----------
4 files changed, 27 insertions(+), 29 deletions(-)
diff --git a/components/publish/PublishLanguagePicker.vue b/components/publish/PublishLanguagePicker.vue
index d0532cc7..6e58d524 100644
--- a/components/publish/PublishLanguagePicker.vue
+++ b/components/publish/PublishLanguagePicker.vue
@@ -1,5 +1,4 @@
-
-
+
+
+
+
{
return length
})
-const postLanguageDisplay = $computed(() => languagesNameList.find(i => i.code === draft.params.language)?.nativeName)
+const postLanguageDisplay = $computed(() => languagesNameList.find(i => i.code === (draft.params.language || preferredLanguage))?.nativeName)
async function handlePaste(evt: ClipboardEvent) {
const files = evt.clipboardData?.files
@@ -290,7 +290,7 @@ defineExpose({
-
+
diff --git a/composables/masto/publish.ts b/composables/masto/publish.ts
index b57466c5..38481006 100644
--- a/composables/masto/publish.ts
+++ b/composables/masto/publish.ts
@@ -4,15 +4,18 @@ import type { mastodon } from 'masto'
import type { UseDraft } from './statusDrafts'
import type { Draft } from '~~/types'
-export const usePublish = (options: {
+export function usePublish(options: {
draftState: UseDraft
expanded: Ref
isUploading: Ref
initialDraft: Ref<() => Draft>
-}) => {
+}) {
const { expanded, isUploading, initialDraft } = $(options)
let { draft, isEmpty } = $(options.draftState)
const { client } = $(useMasto())
+ const settings = useUserSettings()
+
+ const preferredLanguage = $computed(() => (settings.value?.language || 'en').split('-')[0])
let isSending = $ref(false)
const isExpanded = $ref(false)
@@ -31,6 +34,7 @@ export const usePublish = (options: {
async function publishDraft() {
if (isPublishDisabled)
return
+
let content = htmlToText(draft.params.status || '')
if (draft.mentions?.length)
content = `${draft.mentions.map(i => `@${i}`).join(' ')} ${content}`
@@ -39,11 +43,12 @@ export const usePublish = (options: {
...draft.params,
status: content,
mediaIds: draft.attachments.map(a => a.id),
+ language: draft.params.language || preferredLanguage,
...(isGlitchEdition.value ? { 'content-type': 'text/markdown' } : {}),
} as mastodon.v1.CreateStatusParams
if (process.dev) {
- // eslint-disable-next-line no-console
+ // eslint-disable-next-line no-console
console.info({
raw: draft.params.status,
...payload,
@@ -60,6 +65,7 @@ export const usePublish = (options: {
let status: mastodon.v1.Status
if (!draft.editingStatus)
status = await client.v1.statuses.create(payload)
+
else
status = await client.v1.statuses.update(draft.editingStatus.id, payload)
if (draft.params.inReplyToId)
@@ -84,14 +90,14 @@ export const usePublish = (options: {
shouldExpanded,
isPublishDisabled,
failedMessages,
-
+ preferredLanguage,
publishDraft,
})
}
export type MediaAttachmentUploadError = [filename: string, message: string]
-export const useUploadMediaAttachment = (draftRef: Ref) => {
+export function useUploadMediaAttachment(draftRef: Ref) {
const draft = $(draftRef)
const { client } = $(useMasto())
const { t } = useI18n()
@@ -117,7 +123,7 @@ export const useUploadMediaAttachment = (draftRef: Ref) => {
draft.attachments.push(attachment)
}
catch (e) {
- // TODO: add some human-readable error message, problem is that masto api will not return response code
+ // TODO: add some human-readable error message, problem is that masto api will not return response code
console.error(e)
failedAttachments = [...failedAttachments, [file.name, (e as Error).message]]
}
@@ -159,9 +165,10 @@ export const useUploadMediaAttachment = (draftRef: Ref) => {
return $$({
isUploading,
isExceedingAttachmentLimit,
+ isOverDropZone,
+
failedAttachments,
dropZoneRef,
- isOverDropZone,
uploadAttachments,
pickAttachments,
diff --git a/composables/masto/statusDrafts.ts b/composables/masto/statusDrafts.ts
index 567eb017..94598bd4 100644
--- a/composables/masto/statusDrafts.ts
+++ b/composables/masto/statusDrafts.ts
@@ -33,7 +33,7 @@ export function getDefaultDraft(options: Partial()
From 9c3a3de41d8691c00dacd4ddb9c0ae1a19a1b7d4 Mon Sep 17 00:00:00 2001
From: Anthony Fu
Date: Mon, 30 Jan 2023 12:23:49 +0100
Subject: [PATCH 8/9] fix: `initial` default value in PublishWidget
---
components/publish/PublishWidget.vue | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue
index 94b6344b..685cca87 100644
--- a/components/publish/PublishWidget.vue
+++ b/components/publish/PublishWidget.vue
@@ -6,7 +6,7 @@ import type { Draft } from '~/types'
const {
draftKey,
- initial = getDefaultDraft() as never /* Bug of vue-core */,
+ initial = getDefaultDraft,
expanded = false,
placeholder,
dialogLabelledBy,
From 80a4ec502ed766a3c9b19de4a8415c446c83de9c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez?=
Date: Mon, 30 Jan 2023 14:32:27 +0100
Subject: [PATCH 9/9] fix(a11y): allow pinch to zoom (#1515)
---
styles/global.css | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/styles/global.css b/styles/global.css
index 42422eae..a319d903 100644
--- a/styles/global.css
+++ b/styles/global.css
@@ -185,11 +185,6 @@ html {
--at-apply: bg-base text-base;
}
-body {
- /* Prevent arbitrary zooming on mobile devices */
- touch-action: pan-x pan-y;
-}
-
.sparkline--fill {
fill: var(--c-primary-active);
opacity: 0.2;
@@ -214,8 +209,8 @@ footer {
clip-path: url(#avatar-mask);
}
-/*
-Grayscale mode
+/*
+Grayscale mode
Setting each element filter to a different var
allows controlling them individually
*/
@@ -230,7 +225,7 @@ allows controlling them individually
[data-mode="grayscale"] .poll-wrapper {
filter: grayscale(var(--poll-grayscale, 1));
}
-[data-mode="grayscale"] .status-actions,
+[data-mode="grayscale"] .status-actions,
[data-mode="grayscale"] .status-boosted {
filter: grayscale(var(--status-grayscale, 1));
}