2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2022-06-20 10:38:49 +02:00
|
|
|
<MkStickyContainer>
|
2023-08-13 13:12:29 +02:00
|
|
|
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
|
2023-05-19 09:20:53 +02:00
|
|
|
<MkSpacer :contentMax="800">
|
2023-08-13 13:12:29 +02:00
|
|
|
<div class="_gaps">
|
|
|
|
<MkInfo v-if="$i && $i.hasUnreadAnnouncement && tab === 'current'" warn>{{ i18n.ts.youHaveUnreadAnnouncements }}</MkInfo>
|
|
|
|
<MkPagination ref="paginationEl" :key="tab" v-slot="{items}" :pagination="tab === 'current' ? paginationCurrent : paginationPast" class="_gaps">
|
|
|
|
<section v-for="announcement in items" :key="announcement.id" class="_panel" :class="$style.announcement">
|
|
|
|
<div v-if="announcement.forYou" :class="$style.forYou"><i class="ti ti-pin"></i> {{ i18n.ts.forYou }}</div>
|
|
|
|
<div :class="$style.header">
|
2023-11-05 01:04:38 +01:00
|
|
|
<span v-if="$i && !announcement.silence && !announcement.isRead" style="margin-right: 0.5em;">🆕</span>
|
2023-08-13 13:12:29 +02:00
|
|
|
<span style="margin-right: 0.5em;">
|
|
|
|
<i v-if="announcement.icon === 'info'" class="ti ti-info-circle"></i>
|
|
|
|
<i v-else-if="announcement.icon === 'warning'" class="ti ti-alert-triangle" style="color: var(--warn);"></i>
|
|
|
|
<i v-else-if="announcement.icon === 'error'" class="ti ti-circle-x" style="color: var(--error);"></i>
|
|
|
|
<i v-else-if="announcement.icon === 'success'" class="ti ti-check" style="color: var(--success);"></i>
|
|
|
|
</span>
|
|
|
|
<span>{{ announcement.title }}</span>
|
|
|
|
</div>
|
|
|
|
<div :class="$style.content">
|
|
|
|
<Mfm :text="announcement.text"/>
|
|
|
|
<img v-if="announcement.imageUrl" :src="announcement.imageUrl"/>
|
|
|
|
<div style="opacity: 0.7; font-size: 85%;">
|
|
|
|
<MkTime :time="announcement.updatedAt ?? announcement.createdAt" mode="detail"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-11-05 01:04:38 +01:00
|
|
|
<div v-if="tab !== 'past' && $i && !announcement.silence && !announcement.isRead" :class="$style.footer">
|
2023-08-13 13:12:29 +02:00
|
|
|
<MkButton primary @click="read(announcement)"><i class="ti ti-check"></i> {{ i18n.ts.gotIt }}</MkButton>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</MkPagination>
|
|
|
|
</div>
|
2022-06-20 10:38:49 +02:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-01-29 20:37:25 +01:00
|
|
|
</template>
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { ref, computed } from 'vue';
|
2023-12-26 13:40:27 +01:00
|
|
|
import MkPagination, { Paging } from '@/components/MkPagination.vue';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-08-13 13:12:29 +02:00
|
|
|
import MkInfo from '@/components/MkInfo.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
|
|
|
import { $i, updateAccount } from '@/account.js';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-08-13 13:12:29 +02:00
|
|
|
const paginationCurrent = {
|
2022-06-20 10:38:49 +02:00
|
|
|
endpoint: 'announcements' as const,
|
|
|
|
limit: 10,
|
2023-08-13 13:12:29 +02:00
|
|
|
params: {
|
|
|
|
isActive: true,
|
|
|
|
},
|
2023-12-26 13:40:27 +01:00
|
|
|
} satisfies Paging;
|
2023-08-13 13:12:29 +02:00
|
|
|
|
|
|
|
const paginationPast = {
|
|
|
|
endpoint: 'announcements' as const,
|
|
|
|
limit: 10,
|
|
|
|
params: {
|
|
|
|
isActive: false,
|
|
|
|
},
|
2023-12-26 13:40:27 +01:00
|
|
|
} satisfies Paging;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-07-31 07:13:34 +02:00
|
|
|
const paginationEl = ref<InstanceType<typeof MkPagination>>();
|
|
|
|
|
2023-08-13 13:12:29 +02:00
|
|
|
const tab = ref('current');
|
|
|
|
|
|
|
|
async function read(announcement) {
|
|
|
|
if (announcement.needConfirmationToRead) {
|
|
|
|
const confirm = await os.confirm({
|
|
|
|
type: 'question',
|
|
|
|
title: i18n.ts._announcement.readConfirmTitle,
|
|
|
|
text: i18n.t('_announcement.readConfirmText', { title: announcement.title }),
|
|
|
|
});
|
|
|
|
if (confirm.canceled) return;
|
|
|
|
}
|
|
|
|
|
2023-07-31 07:13:34 +02:00
|
|
|
if (!paginationEl.value) return;
|
2023-08-13 13:12:29 +02:00
|
|
|
paginationEl.value.updateItem(announcement.id, a => {
|
|
|
|
a.isRead = true;
|
|
|
|
return a;
|
|
|
|
});
|
|
|
|
os.api('i/read-announcement', { announcementId: announcement.id });
|
|
|
|
updateAccount({
|
|
|
|
unreadAnnouncements: $i!.unreadAnnouncements.filter(a => a.id !== announcement.id),
|
2023-07-31 07:13:34 +02:00
|
|
|
});
|
2022-06-20 10:38:49 +02:00
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const headerActions = computed(() => []);
|
2022-06-20 10:38:49 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const headerTabs = computed(() => [{
|
2023-08-13 13:12:29 +02:00
|
|
|
key: 'current',
|
|
|
|
title: i18n.ts.currentAnnouncements,
|
|
|
|
icon: 'ti ti-flare',
|
|
|
|
}, {
|
|
|
|
key: 'past',
|
|
|
|
title: i18n.ts.pastAnnouncements,
|
|
|
|
icon: 'ti ti-point',
|
|
|
|
}]);
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.announcements,
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-speakerphone',
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-08-13 13:12:29 +02:00
|
|
|
<style lang="scss" module>
|
|
|
|
.announcement {
|
|
|
|
padding: 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.forYou {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
line-height: 24px;
|
|
|
|
font-size: 90%;
|
|
|
|
white-space: pre;
|
|
|
|
color: #d28a3f;
|
|
|
|
}
|
|
|
|
|
|
|
|
.header {
|
|
|
|
margin-bottom: 16px;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
.content {
|
|
|
|
> img {
|
|
|
|
display: block;
|
|
|
|
max-height: 300px;
|
|
|
|
max-width: 100%;
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
2023-08-13 13:12:29 +02:00
|
|
|
|
|
|
|
.footer {
|
|
|
|
margin-top: 16px;
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
</style>
|