Add swiper to notifications

This commit is contained in:
ThatOneCalculator 2022-09-09 15:44:55 -07:00
parent b5df90c797
commit 3b3e8b5f51
1 changed files with 40 additions and 9 deletions

View File

@ -9,21 +9,34 @@
/> />
</template> </template>
<MkSpacer :content-max="800"> <MkSpacer :content-max="800">
<div v-if="tab === 'all' || tab === 'unread'"> <swiper
<XNotifications class="notifications" :include-types="includeTypes" :unread-only="unreadOnly"/> :modules="[Virtual]"
</div> :space-between="20"
<div v-else-if="tab === 'mentions'"> :virtual="true"
<XNotes :pagination="mentionsPagination"/> @swiper="setSwiperRef"
</div> @slide-change="onSlideChange"
<div v-else-if="tab === 'directNotes'"> >
<XNotes :pagination="directNotesPagination"/> <swiper-slide>
</div> <XNotifications class="notifications" :include-types="includeTypes" :unread-only="false"/>
</swiper-slide>
<swiper-slide>
<XNotifications class="notifications" :include-types="includeTypes" :unread-only="true"/>
</swiper-slide>
<swiper-slide>
<XNotes :pagination="mentionsPagination"/>
</swiper-slide>
<swiper-slide>
<XNotes :pagination="directNotesPagination"/>
</swiper-slide>
</swiper>
</MkSpacer> </MkSpacer>
</MkStickyContainer> </MkStickyContainer>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { Virtual } from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/vue';
import { notificationTypes } from 'misskey-js'; import { notificationTypes } from 'misskey-js';
import XNotifications from '@/components/MkNotifications.vue'; import XNotifications from '@/components/MkNotifications.vue';
import XNotes from '@/components/MkNotes.vue'; import XNotes from '@/components/MkNotes.vue';
@ -31,8 +44,11 @@ import * as os from '@/os';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata'; import { definePageMetadata } from '@/scripts/page-metadata';
import { deviceKind } from '@/scripts/device-kind'; import { deviceKind } from '@/scripts/device-kind';
import 'swiper/scss';
import 'swiper/scss/virtual';
let tab = $ref('all'); let tab = $ref('all');
const tabs = ['all', 'unread', 'mentions', 'directNotes'];
let includeTypes = $ref<string[] | null>(null); let includeTypes = $ref<string[] | null>(null);
let unreadOnly = $computed(() => tab === 'unread'); let unreadOnly = $computed(() => tab === 'unread');
os.api('notifications/mark-all-as-read'); os.api('notifications/mark-all-as-read');
@ -112,4 +128,19 @@ definePageMetadata(computed(() => ({
title: i18n.ts.notifications, title: i18n.ts.notifications,
icon: 'fas fa-bell', icon: 'fas fa-bell',
}))); })));
let swiperRef = null;
function setSwiperRef(swiper) {
swiperRef = swiper;
syncSlide(tabs.indexOf(tab));
}
function onSlideChange() {
tab = tabs[swiperRef.activeIndex];
}
function syncSlide(index) {
swiperRef.slideTo(index);
}
</script> </script>