2023-08-15 02:52:38 +09:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2022-06-20 17:38:49 +09:00
|
|
|
<MkStickyContainer>
|
2023-08-18 08:03:03 +09:00
|
|
|
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
|
2023-05-19 16:20:53 +09:00
|
|
|
<MkSpacer :contentMax="800">
|
2023-08-18 08:03:03 +09: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">
|
|
|
|
<span v-if="$i && !announcement.isRead" style="margin-right: 0.5em;">🆕</span>
|
|
|
|
<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>
|
2023-08-19 04:48:28 +09:00
|
|
|
<Mfm :text="announcement.title"/>
|
2023-08-18 08:03:03 +09:00
|
|
|
</div>
|
|
|
|
<div :class="$style.content">
|
|
|
|
<Mfm :text="announcement.text"/>
|
|
|
|
<img v-if="announcement.imageUrl" :src="announcement.imageUrl"/>
|
2023-08-23 00:59:45 +09:00
|
|
|
<div style="margin-top: 8px; opacity: 0.7; font-size: 85%;">
|
2023-08-18 08:03:03 +09:00
|
|
|
<MkTime :time="announcement.updatedAt ?? announcement.createdAt" mode="detail"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-if="tab !== 'past' && $i && !announcement.isRead" :class="$style.footer">
|
|
|
|
<MkButton primary @click="read(announcement)"><i class="ti ti-check"></i> {{ i18n.ts.gotIt }}</MkButton>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</MkPagination>
|
|
|
|
</div>
|
2022-06-20 17:38:49 +09:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
|
2022-06-20 17:38:49 +09:00
|
|
|
<script lang="ts" setup>
|
2023-08-19 04:48:28 +09:00
|
|
|
import { ref, watch } from 'vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import * as os from '@/os';
|
2022-06-20 17:38:49 +09:00
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2023-08-18 08:03:03 +09:00
|
|
|
import { $i, updateAccount } from '@/account';
|
2023-08-19 04:48:28 +09:00
|
|
|
import MkPagination from '@/components/MkPagination.vue';
|
|
|
|
import MkButton from '@/components/MkButton.vue';
|
|
|
|
import MkInfo from '@/components/MkInfo.vue';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-08-18 08:03:03 +09:00
|
|
|
const paginationCurrent = {
|
2022-06-20 17:38:49 +09:00
|
|
|
endpoint: 'announcements' as const,
|
2023-08-19 04:48:28 +09:00
|
|
|
offsetMode: true,
|
2022-06-20 17:38:49 +09:00
|
|
|
limit: 10,
|
2023-08-18 08:03:03 +09:00
|
|
|
params: {
|
|
|
|
isActive: true,
|
|
|
|
},
|
2022-06-20 17:38:49 +09:00
|
|
|
};
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-08-18 08:03:03 +09:00
|
|
|
const paginationPast = {
|
|
|
|
endpoint: 'announcements' as const,
|
2023-08-19 04:48:28 +09:00
|
|
|
offsetMode: true,
|
2023-08-18 08:03:03 +09:00
|
|
|
limit: 10,
|
|
|
|
params: {
|
|
|
|
isActive: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const paginationEl = ref<InstanceType<typeof MkPagination>>();
|
|
|
|
const tab = ref('current');
|
|
|
|
|
2023-08-19 04:48:28 +09:00
|
|
|
async function read(announcement): Promise<void> {
|
2023-08-18 08:03:03 +09:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!paginationEl.value) return;
|
|
|
|
paginationEl.value.updateItem(announcement.id, a => {
|
|
|
|
a.isRead = true;
|
|
|
|
return a;
|
|
|
|
});
|
2023-08-19 04:48:28 +09:00
|
|
|
await os.api('i/read-announcement', { announcementId: announcement.id });
|
|
|
|
if ($i) {
|
|
|
|
updateAccount({
|
|
|
|
unreadAnnouncements: $i.unreadAnnouncements.filter((a: { id: string; }) => a.id !== announcement.id),
|
|
|
|
});
|
|
|
|
}
|
2022-06-20 17:38:49 +09:00
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-06-20 17:38:49 +09:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
2023-08-18 08:03:03 +09:00
|
|
|
const headerTabs = $computed(() => [{
|
|
|
|
key: 'current',
|
|
|
|
title: i18n.ts.currentAnnouncements,
|
|
|
|
icon: 'ti ti-flare',
|
|
|
|
}, {
|
|
|
|
key: 'past',
|
|
|
|
title: i18n.ts.pastAnnouncements,
|
|
|
|
icon: 'ti ti-point',
|
|
|
|
}]);
|
2022-06-20 17:38:49 +09:00
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.announcements,
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-speakerphone',
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
2023-08-19 04:48:28 +09:00
|
|
|
|
|
|
|
const unreadCount = ref($i?.unreadAnnouncements.length ?? 0);
|
|
|
|
watch(() => $i?.unreadAnnouncements.length ?? 0, () => {
|
|
|
|
// 未読が増えた場合はリロード
|
|
|
|
if (($i?.unreadAnnouncements.length ?? 0) > unreadCount.value) {
|
|
|
|
paginationEl.value?.reload();
|
|
|
|
}
|
|
|
|
unreadCount.value = $i?.unreadAnnouncements.length ?? 0;
|
|
|
|
});
|
2020-01-30 04:37:25 +09:00
|
|
|
</script>
|
|
|
|
|
2023-08-18 08:03:03 +09: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;
|
2023-08-23 00:59:45 +09:00
|
|
|
font-size: 120%;
|
2023-08-18 08:03:03 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
.content {
|
|
|
|
> img {
|
|
|
|
display: block;
|
|
|
|
max-height: 300px;
|
|
|
|
max-width: 100%;
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
}
|
2023-08-18 08:03:03 +09:00
|
|
|
|
|
|
|
.footer {
|
|
|
|
margin-top: 16px;
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
</style>
|