2024-04-27 03:28:12 +02:00
|
|
|
<template>
|
|
|
|
|
<div class="flex flex-col p-1 bg-dark-400">
|
|
|
|
|
<div class="px-4 pt-2 pb-3 flex flex-row gap-2 items-center">
|
|
|
|
|
<Skeleton :enabled="!notification" shape="rect" class="!h-6" :min-width="40" :max-width="100"
|
|
|
|
|
width-unit="%">
|
2024-05-12 11:04:00 +02:00
|
|
|
<iconify-icon :icon="icon" width="1.5rem" height="1.5rem" class="text-gray-200" aria-hidden="true" />
|
2024-06-21 04:09:09 +02:00
|
|
|
<Avatar v-if="notification?.account?.avatar" :src="notification?.account.avatar"
|
2024-05-03 05:28:31 +02:00
|
|
|
:alt="`${notification?.account.acct}'s avatar'`"
|
|
|
|
|
class="h-6 w-6 shrink-0 rounded ring-1 ring-white/10" />
|
2024-06-19 08:16:28 +02:00
|
|
|
<span class="text-gray-200 line-clamp-1"><strong v-html="display_name"></strong> {{ text
|
2024-04-28 07:02:27 +02:00
|
|
|
}}</span>
|
2024-04-27 03:28:12 +02:00
|
|
|
</Skeleton>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
2024-06-21 04:09:09 +02:00
|
|
|
<Note v-if="notification?.status || !notification" :note="notification?.status" :small="true" />
|
2024-04-27 03:28:12 +02:00
|
|
|
<div v-else-if="notification.account" class="p-6 ring-1 ring-white/5 bg-dark-800">
|
2024-06-21 04:09:09 +02:00
|
|
|
<SmallCard :account="notification.account" />
|
2024-04-27 03:28:12 +02:00
|
|
|
</div>
|
2024-06-12 02:03:30 +02:00
|
|
|
<div v-if="notification?.type === 'follow_request' && relationship?.requested_by"
|
|
|
|
|
class="w-full grid grid-cols-2 gap-4 p-2 ">
|
2024-06-21 04:09:09 +02:00
|
|
|
<ButtonPrimary :loading="isWorkingOnFollowRequest" @click="acceptFollowRequest"><span>Accept</span>
|
|
|
|
|
</ButtonPrimary>
|
|
|
|
|
<ButtonSecondary :loading="isWorkingOnFollowRequest" @click="rejectFollowRequest"><span>Reject</span>
|
|
|
|
|
</ButtonSecondary>
|
2024-06-12 02:03:30 +02:00
|
|
|
</div>
|
2024-04-27 03:28:12 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-06-21 04:09:09 +02:00
|
|
|
import type { Notification } from "@lysand-org/client/types";
|
|
|
|
|
import Avatar from "~/components/avatars/avatar.vue";
|
|
|
|
|
import ButtonPrimary from "~/components/buttons/button-primary.vue";
|
|
|
|
|
import ButtonSecondary from "~/components/buttons/button-secondary.vue";
|
|
|
|
|
import Skeleton from "~/components/skeleton/Skeleton.vue";
|
|
|
|
|
import Note from "../notes/note.vue";
|
|
|
|
|
import SmallCard from "../users/SmallCard.vue";
|
2024-04-27 03:28:12 +02:00
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
notification?: Notification;
|
|
|
|
|
}>();
|
|
|
|
|
|
2024-06-12 02:03:30 +02:00
|
|
|
const client = useClient();
|
|
|
|
|
const isWorkingOnFollowRequest = ref(false);
|
|
|
|
|
const { relationship } = useRelationship(
|
|
|
|
|
client,
|
|
|
|
|
props.notification?.account?.id ?? null,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const acceptFollowRequest = async () => {
|
2024-06-20 02:07:56 +02:00
|
|
|
if (!props.notification?.account) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-12 02:03:30 +02:00
|
|
|
isWorkingOnFollowRequest.value = true;
|
|
|
|
|
const { data } = await client.value.acceptFollowRequest(
|
|
|
|
|
props.notification.account.id,
|
|
|
|
|
);
|
2024-06-12 03:02:30 +02:00
|
|
|
relationship.value = data;
|
2024-06-12 02:03:30 +02:00
|
|
|
isWorkingOnFollowRequest.value = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const rejectFollowRequest = async () => {
|
2024-06-20 02:07:56 +02:00
|
|
|
if (!props.notification?.account) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-12 02:03:30 +02:00
|
|
|
isWorkingOnFollowRequest.value = true;
|
|
|
|
|
const { data } = await client.value.rejectFollowRequest(
|
|
|
|
|
props.notification.account.id,
|
|
|
|
|
);
|
2024-06-12 03:02:30 +02:00
|
|
|
relationship.value = data;
|
2024-06-12 02:03:30 +02:00
|
|
|
isWorkingOnFollowRequest.value = false;
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-19 08:16:28 +02:00
|
|
|
const settings = useSettings();
|
|
|
|
|
const { display_name } = useParsedAccount(
|
|
|
|
|
props.notification?.account,
|
|
|
|
|
settings,
|
2024-04-27 06:50:30 +02:00
|
|
|
);
|
2024-06-19 08:16:28 +02:00
|
|
|
|
2024-04-27 03:28:12 +02:00
|
|
|
const text = computed(() => {
|
2024-06-20 02:07:56 +02:00
|
|
|
if (!props.notification) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2024-04-27 03:28:12 +02:00
|
|
|
|
|
|
|
|
switch (props.notification.type) {
|
2024-04-27 06:50:30 +02:00
|
|
|
case "mention":
|
|
|
|
|
return "mentioned you";
|
|
|
|
|
case "reblog":
|
|
|
|
|
return "reblogged your note";
|
|
|
|
|
case "favourite":
|
|
|
|
|
return "liked your note";
|
|
|
|
|
case "follow":
|
|
|
|
|
return "followed you";
|
|
|
|
|
case "follow_request":
|
|
|
|
|
return "requested to follow you";
|
2024-06-20 02:07:56 +02:00
|
|
|
default: {
|
2024-04-27 06:50:30 +02:00
|
|
|
console.error("Unknown notification type", props.notification.type);
|
|
|
|
|
return "";
|
2024-06-20 02:07:56 +02:00
|
|
|
}
|
2024-04-27 03:28:12 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
const icon = computed(() => {
|
2024-06-20 02:07:56 +02:00
|
|
|
if (!props.notification) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2024-04-27 03:28:12 +02:00
|
|
|
|
|
|
|
|
switch (props.notification.type) {
|
2024-04-27 06:50:30 +02:00
|
|
|
case "mention":
|
|
|
|
|
return "tabler:at";
|
|
|
|
|
case "reblog":
|
|
|
|
|
return "tabler:repeat";
|
|
|
|
|
case "favourite":
|
|
|
|
|
return "tabler:heart";
|
|
|
|
|
case "follow":
|
|
|
|
|
return "tabler:plus";
|
|
|
|
|
case "follow_request":
|
|
|
|
|
return "tabler:plus";
|
2024-04-27 03:28:12 +02:00
|
|
|
default:
|
2024-04-27 06:50:30 +02:00
|
|
|
return "";
|
2024-04-27 03:28:12 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
</script>
|