diff --git a/src/components/friends/FriendListItem.vue b/src/components/friends/FriendListItem.vue new file mode 100644 index 0000000..71953f9 --- /dev/null +++ b/src/components/friends/FriendListItem.vue @@ -0,0 +1,62 @@ + + + \ No newline at end of file diff --git a/src/layouts/settings.vue b/src/layouts/settings.vue index 589daa2..f281aac 100644 --- a/src/layouts/settings.vue +++ b/src/layouts/settings.vue @@ -6,8 +6,15 @@
- + + + + + + + + diff --git a/src/router/settings.ts b/src/router/settings.ts index 42bf72a..4d91297 100644 --- a/src/router/settings.ts +++ b/src/router/settings.ts @@ -5,6 +5,12 @@ export const settingRouter = [ component: () => import("@/views/settings.vue") }, + { + path: "account/friends", + name: "settings.account.friends", + component: () => import("@/views/users/me/friends.vue") + }, + { path: "account/personalize", name: "settings.account.personalize", diff --git a/src/stores/friends.ts b/src/stores/friends.ts new file mode 100644 index 0000000..dd28695 --- /dev/null +++ b/src/stores/friends.ts @@ -0,0 +1,23 @@ +import { reactive, ref } from "vue" +import { defineStore } from "pinia" +import { checkLoggedIn, getAtk } from "@/stores/userinfo" +import { request } from "@/scripts/request" + +export const useFriends = defineStore("friends", () => { + const available = ref([]) + + async function list() { + if (!(await checkLoggedIn())) return + + const res = await request("identity", "/api/users/me/friends?status=1", { + headers: { Authorization: `Bearer ${await getAtk()}` } + }) + if (res.status !== 200) { + throw new Error(await res.text()) + } else { + available.value = await res.json() + } + } + + return { available, list } +}) diff --git a/src/stores/userinfo.ts b/src/stores/userinfo.ts index 81aef2a..9203380 100644 --- a/src/stores/userinfo.ts +++ b/src/stores/userinfo.ts @@ -4,6 +4,7 @@ import { request } from "@/scripts/request" import { Preferences } from "@capacitor/preferences" import { useRealms } from "@/stores/realms" import { useChannels } from "@/stores/channels" +import { useFriends } from "@/stores/friends" export interface Userinfo { isReady: boolean @@ -51,7 +52,7 @@ export async function signout() { export const useUserinfo = defineStore("userinfo", () => { const userinfoHooks = { - after: [useRealms().list, useChannels().list, useChannels().connect] + after: [useRealms().list, useChannels().list, useChannels().connect, useFriends().list] } const userinfo = ref(defaultUserinfo) diff --git a/src/views/users/me/friends.vue b/src/views/users/me/friends.vue new file mode 100644 index 0000000..fee68ca --- /dev/null +++ b/src/views/users/me/friends.vue @@ -0,0 +1,144 @@ + + + \ No newline at end of file diff --git a/src/views/users/me/personalize.vue b/src/views/users/me/personalize.vue index 1feb96d..022eb10 100644 --- a/src/views/users/me/personalize.vue +++ b/src/views/users/me/personalize.vue @@ -45,7 +45,7 @@ icon="mdi-account-circle" class="rounded-card" size="large" - :image="accountPicture ?? ''" + :image="accountPicture" /> @@ -191,11 +191,11 @@ function loadImage(event: InputEvent, type: string) { const accountPicture = computed(() => id.userinfo.data?.avatar ? buildRequestUrl("identity", `/api/avatar/${id.userinfo.data?.avatar}`) : - null + undefined ) const accountBanner = computed(() => id.userinfo.data?.banner ? buildRequestUrl("identity", `/api/avatar/${id.userinfo.data?.banner}`) : - null + undefined ) onUnmounted(() => { diff --git a/src/views/users/page.vue b/src/views/users/page.vue index 461d981..73e96d1 100644 --- a/src/views/users/page.vue +++ b/src/views/users/page.vue @@ -9,7 +9,7 @@ color="grey-lighten-2" icon="mdi-account-circle" class="rounded-card me-2" - :image="accountPicture ?? ''" + :image="accountPicture" />
@@ -100,11 +100,11 @@ const posts = ref([]) const accountPicture = computed(() => metadata.value?.avatar ? buildRequestUrl("identity", `/api/avatar/${metadata.value?.avatar}`) : - null + undefined ) const accountBanner = computed(() => metadata.value?.banner ? buildRequestUrl("identity", `/api/avatar/${metadata.value?.banner}`) : - null + undefined ) async function readMetadata() {