slightly better status, internationalization

This commit is contained in:
sam 2023-12-20 03:24:38 +01:00
parent 7c5acad535
commit a06dd22da4
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
22 changed files with 2416 additions and 1009 deletions

View file

@ -1,15 +1,15 @@
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')
require("@rushstack/eslint-patch/modern-module-resolution");
module.exports = {
root: true,
'extends': [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/eslint-config-typescript',
'@vue/eslint-config-prettier/skip-formatting'
],
parserOptions: {
ecmaVersion: 'latest'
}
}
root: true,
extends: [
"plugin:vue/vue3-essential",
"eslint:recommended",
"@vue/eslint-config-typescript",
"@vue/eslint-config-prettier/skip-formatting",
],
parserOptions: {
ecmaVersion: "latest",
},
};

View file

@ -1,8 +1,8 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": true,
"useTabs": true,
"singleQuote": false,
"printWidth": 100,
"trailingComma": "all"
"$schema": "https://json.schemastore.org/prettierrc",
"semi": true,
"useTabs": true,
"singleQuote": false,
"printWidth": 100,
"trailingComma": "all"
}

View file

@ -1,8 +1,8 @@
{
"recommendations": [
"Vue.volar",
"Vue.vscode-typescript-vue-plugin",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
"recommendations": [
"Vue.volar",
"Vue.vscode-typescript-vue-plugin",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}

View file

@ -13,8 +13,8 @@ TypeScript cannot handle type information for `.vue` imports by default, so we r
If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:
1. Disable the built-in TypeScript Extension
1) Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2) Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
1. Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2. Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
## Customize configuration

1
env.d.ts vendored
View file

@ -1 +1,2 @@
/// <reference types="vite/client" />
/// <reference types="@modyfi/vite-plugin-yaml/modules" />

View file

@ -1,13 +1,13 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

View file

@ -1,44 +1,47 @@
{
"name": "vulpine-fe",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"build-only": "vite build",
"type-check": "vue-tsc --build --force",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"format": "prettier --write src/"
},
"dependencies": {
"axios": "^1.6.2",
"flowbite": "^2.2.1",
"flowbite-vue": "^0.1.2",
"pinia": "^2.1.7",
"sass": "^1.69.5",
"swrv": "^1.0.4",
"vue": "^3.3.11",
"vue-router": "^4.2.5"
},
"devDependencies": {
"@rushstack/eslint-patch": "^1.3.3",
"@tsconfig/node18": "^18.2.2",
"@types/node": "^18.19.3",
"@vitejs/plugin-vue": "^4.5.2",
"@vue/eslint-config-prettier": "^8.0.0",
"@vue/eslint-config-typescript": "^12.0.0",
"@vue/tsconfig": "^0.5.0",
"autoprefixer": "^10.4.16",
"eslint": "^8.49.0",
"eslint-plugin-vue": "^9.17.0",
"npm-run-all2": "^6.1.1",
"postcss": "^8.4.32",
"prettier": "^3.0.3",
"tailwindcss": "^3.3.7",
"typescript": "~5.3.0",
"vite": "^5.0.10",
"vue-tsc": "^1.8.25"
}
"name": "vulpine-fe",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"build-only": "vite build",
"type-check": "vue-tsc --build --force",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"format": "prettier --write ."
},
"dependencies": {
"@tabler/icons-vue": "^2.44.0",
"axios": "^1.6.2",
"flowbite": "^2.2.1",
"flowbite-vue": "^0.1.2",
"pinia": "^2.1.7",
"sass": "^1.69.5",
"swrv": "^1.0.4",
"vue": "^3.3.11",
"vue-i18n": "9",
"vue-router": "^4.2.5"
},
"devDependencies": {
"@modyfi/vite-plugin-yaml": "^1.0.4",
"@rushstack/eslint-patch": "^1.3.3",
"@tsconfig/node18": "^18.2.2",
"@types/node": "^18.19.3",
"@vitejs/plugin-vue": "^4.5.2",
"@vue/eslint-config-prettier": "^8.0.0",
"@vue/eslint-config-typescript": "^12.0.0",
"@vue/tsconfig": "^0.5.0",
"autoprefixer": "^10.4.16",
"eslint": "^8.49.0",
"eslint-plugin-vue": "^9.17.0",
"npm-run-all2": "^6.1.1",
"postcss": "^8.4.32",
"prettier": "^3.0.3",
"tailwindcss": "^3.3.7",
"typescript": "~5.3.0",
"vite": "^5.0.10",
"vue-tsc": "^1.8.25"
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};

View file

@ -1,7 +1,36 @@
<script setup lang="ts">
import { useI18n } from "vue-i18n";
import type Activity from "@/lib/api/entities/activity";
import { IconWorld, IconHome, IconLock, IconMail } from "@tabler/icons-vue";
const { t } = useI18n();
defineProps<{ status: Activity }>();
const statusScopeKey = ({ visibility }: Activity) => {
switch (visibility) {
case "direct":
return "status.visibility.directMessage";
case "private":
return "status.visibility.followersOnly";
case "unlisted":
return "status.visibility.unlisted";
case "public":
return "status.visibility.public";
}
};
const statusScopeIcon = ({ visibility }: Activity) => {
switch (visibility) {
case "direct":
return IconMail
case "private":
return IconLock
case "unlisted":
return IconHome
case "public":
return IconWorld
}
}
</script>
<template>
@ -12,8 +41,8 @@ defineProps<{ status: Activity }>();
class="rounded-full m-2"
:src="status.account.avatar"
width="64"
alt="Avatar for {{ status.account.acct }}"
title="Avatar for {{ status.account.acct }}"
:alt="t('status.avatar', { name: status.account.acct })"
:title="t('status.avatar', { name: status.account.acct })"
/>
</RouterLink>
<div class="flex flex-col my-1">
@ -29,11 +58,10 @@ defineProps<{ status: Activity }>();
</div>
<div class="my-1 flex flex-row">
<span>
<span title="{t(statusScopeKey(status))}" aria-hidden="true">
<!-- <StatusScopeIcon status="{status}" /> -->
Public
<span :title="t(statusScopeKey(status))" aria-hidden="true">
<component :is="statusScopeIcon(status)" />
</span>
<span class="sr-only">{t(statusScopeKey(status))}</span>
<span class="sr-only">{{ t(statusScopeKey(status)) }}</span>
</span>
<RouterLink :to="`/@${status.account.acct}/statuses/${status.id}`">
{humanizeDuration(time)}

35
src/i18n.ts Normal file
View file

@ -0,0 +1,35 @@
import { nextTick } from "vue";
import { createI18n } from "vue-i18n";
import en from "./locale/en.yaml";
export const supportedLocales = ["en", "en-PR"];
export const i18n = createI18n({
legacy: false,
locale: "en",
messages: {
en: en,
},
});
export function setLanguage(locale: string) {
// @ts-ignore
i18n.global.locale.value = locale;
document.querySelector("html")!.setAttribute("lang", locale);
}
export async function loadLocale(locale: string) {
// Check if the locale is already loaded. If not, return
// @ts-ignore
if (i18n.global.availableLocales.indexOf(locale) !== -1) return;
if (supportedLocales.indexOf(locale) === -1) throw `${locale} is not a valid locale`;
const messages = await locales[locale as keyof typeof locales]();
i18n.global.setLocaleMessage(locale, messages.default);
return nextTick();
}
const locales = {
"en-PR": () => import("./locale/en.pirate.yaml"),
};

View file

@ -1,48 +1,48 @@
import type { CustomEmoji } from "./custom_emoji";
export interface Account {
id: string;
/** Username, not including domain */
username: string;
/** Webfinger account URI */
acct: string;
/** The user's profile page */
url: string;
/** The user's nickname/display name */
display_name: string;
/** The user's bio */
note: string;
/** The user's avatar URL */
avatar: string;
/** The user's avatar URL as a static image. Same as `avatar` if the avatar is not animated */
avatar_static: string;
/** The user's header URL */
header: string;
/** The user's header URL as a static image. Same as `header` if the header is not animated */
header_static: string;
/** Whether the account manually approves follow requests */
locked: boolean;
/** Additional metadata attached to a profile as name-value pairs */
fields: Field[];
/** Custom emoji entities to be used when rendering the profile */
emojis: CustomEmoji[];
/** Indicates that the account may perform automated actions, may not be monitored, or identifies as a robot */
bot: boolean;
/** When the account was created */
created_at: string;
/** When the most recent status was posted */
last_status_at: string | null;
/** How many statuses are attached to this account */
statuses_count: number;
/** The reported followers of this profile */
followers_count: number;
/** The reported follows of this profile */
following_count: number;
}
export interface Account {
id: string;
/** Username, not including domain */
username: string;
/** Webfinger account URI */
acct: string;
/** The user's profile page */
url: string;
/** The user's nickname/display name */
display_name: string;
/** The user's bio */
note: string;
/** The user's avatar URL */
avatar: string;
/** The user's avatar URL as a static image. Same as `avatar` if the avatar is not animated */
avatar_static: string;
/** The user's header URL */
header: string;
/** The user's header URL as a static image. Same as `header` if the header is not animated */
header_static: string;
/** Whether the account manually approves follow requests */
locked: boolean;
/** Additional metadata attached to a profile as name-value pairs */
fields: Field[];
/** Custom emoji entities to be used when rendering the profile */
emojis: CustomEmoji[];
/** Indicates that the account may perform automated actions, may not be monitored, or identifies as a robot */
bot: boolean;
/** When the account was created */
created_at: string;
/** When the most recent status was posted */
last_status_at: string | null;
/** How many statuses are attached to this account */
statuses_count: number;
/** The reported followers of this profile */
followers_count: number;
/** The reported follows of this profile */
following_count: number;
}
export interface Field {
/** The key of a given fields key-value pair */
name: string;
/** The value associated with the name key */
value: string;
}
export interface Field {
/** The key of a given fields key-value pair */
name: string;
/** The value associated with the name key */
value: string;
}

32
src/locale/en.pirate.yaml Normal file
View file

@ -0,0 +1,32 @@
status:
avatar: "{name}'s mugshot"
characterCount: "{count} character | {count} characters"
showContent: "Show treasure ({@:status.characterCount})"
hideContent: "Hide treasure ({@:status.characterCount})"
visibility:
directMessage: Direct bottle
followersOnly: Only shown to their mateys
unlisted: Quietly thrown in the sea
public: Free as the wind
navbar:
homeTimeine: Yar friends' bottles
localTimeline: Ship's bottles
bubbleTimeline: Fleet's bottles
globalTimeline: The seven seas
settings: Yar pref'rences
login: Report fer duty
logout: Go to sleep
settings:
darkTheme: Like the moon's out
lightTheme: Like the sun's out
sidebar:
postbox:
placeholder: What be happening on deck?
postButton: Roll up an' send
directMessage: Direct bottle
followersOnly: Only send to yer mateys
unlisted: Quietly throw in the sea
public: Post free as the wind
emojiButton: Draw lil' faces
pollButton: Start a vote
fileButton: Draw images

32
src/locale/en.yaml Normal file
View file

@ -0,0 +1,32 @@
status:
avatar: "{name}'s avatar"
characterCount: "{count} character | {count} characters"
showContent: "Show content ({@:status.characterCount})"
hideContent: "Hide content ({@:status.characterCount})"
visibility:
directMessage: Direct message
followersOnly: Followers only
unlisted: Unlisted
public: Public
navbar:
homeTimeine: Home timeline
localTimeline: Local timeline
bubbleTimeline: Bubble timeline
globalTimeline: Global timeline
settings: Settings
login: Log in
logout: Log out
settings:
darkTheme: Dark theme
lightTheme: Light theme
sidebar:
postbox:
placeholder: What's going on?
postButton: Post
directMessage: Direct message
followersOnly: Followers only
unlisted: Unlisted
public: Public
emojiButton: Emoji
pollButton: Create poll
fileButton: Attach a file

View file

@ -2,6 +2,7 @@ import "./assets/style.css";
import { createApp } from "vue";
import { createPinia } from "pinia";
import { i18n } from "./i18n";
import App from "./App.vue";
import router from "./router";
@ -10,5 +11,6 @@ const app = createApp(App);
app.use(createPinia());
app.use(router);
app.use(i18n);
app.mount("#app");

View file

@ -6,24 +6,24 @@ import { ref } from "vue";
const localStorageKey = "vulpine-oauth-app";
export const useAppStore = defineStore("oauth-app", () => {
const json = localStorage.getItem(localStorageKey)
const app = ref<Application>(json ? JSON.parse(json) : undefined);
const json = localStorage.getItem(localStorageKey);
const app = ref<Application>(json ? JSON.parse(json) : undefined);
async function getApp() {
if (app.value) return app.value;
async function getApp() {
if (app.value) return app.value;
const resp = await apiFetch<Application>("/api/v1/apps", {
method: "POST",
body: {
client_name: "vulpine-fe",
redirect_uris: `${window.location.origin}/auth/callback`,
scopes: "read write follow push",
}
})
app.value = resp;
localStorage.setItem(localStorageKey, JSON.stringify(resp));
return app.value;
}
const resp = await apiFetch<Application>("/api/v1/apps", {
method: "POST",
body: {
client_name: "vulpine-fe",
redirect_uris: `${window.location.origin}/auth/callback`,
scopes: "read write follow push",
},
});
app.value = resp;
localStorage.setItem(localStorageKey, JSON.stringify(resp));
return app.value;
}
return { app, getApp }
})
return { app, getApp };
});

View file

@ -35,6 +35,7 @@ watch(
},
);
</script>
<template>
<div v-if="error">Failed to load: {{ error }}</div>
<FwbSpinner v-else-if="!data" size="10" />

View file

@ -1,14 +1,14 @@
/** @type {import('tailwindcss').Config} */
export default {
darkMode: "class",
content: [
"./index.html",
"./src/**/*.{vue,js,ts,jsx,tsx}",
'node_modules/flowbite-vue/**/*.{js,jsx,ts,tsx,vue}',
'node_modules/flowbite/**/*.{js,jsx,ts,tsx}',
],
theme: {
extend: {},
},
plugins: [import('flowbite/plugin')],
}
darkMode: "class",
content: [
"./index.html",
"./src/**/*.{vue,js,ts,jsx,tsx}",
"node_modules/flowbite-vue/**/*.{js,jsx,ts,tsx,vue}",
"node_modules/flowbite/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {},
},
plugins: [import("flowbite/plugin")],
};

View file

@ -1,13 +1,13 @@
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"composite": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
"extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"composite": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}

View file

@ -1,11 +1,11 @@
{
"files": [],
"references": [
{
"path": "./tsconfig.node.json"
},
{
"path": "./tsconfig.app.json"
}
]
"files": [],
"references": [
{
"path": "./tsconfig.node.json"
},
{
"path": "./tsconfig.app.json"
}
]
}

View file

@ -1,17 +1,17 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"include": [
"vite.config.*",
"vitest.config.*",
"cypress.config.*",
"nightwatch.conf.*",
"playwright.config.*"
],
"compilerOptions": {
"composite": true,
"noEmit": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"types": ["node"]
}
"extends": "@tsconfig/node18/tsconfig.json",
"include": [
"vite.config.*",
"vitest.config.*",
"cypress.config.*",
"nightwatch.conf.*",
"playwright.config.*"
],
"compilerOptions": {
"composite": true,
"noEmit": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"types": ["node"]
}
}

View file

@ -2,13 +2,14 @@ import { fileURLToPath, URL } from "node:url";
import { loadEnv, defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import yaml from "@modyfi/vite-plugin-yaml";
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const { INSTANCE } = loadEnv(mode, process.cwd(), "");
return {
plugins: [vue()],
plugins: [vue(), yaml()],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),