Sharkey/packages/frontend/src/pages/my-clips/index.vue

116 lines
2.8 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
2022-07-20 15:24:26 +02:00
<template>
<MkStickyContainer>
2023-03-16 09:24:49 +01:00
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
2023-05-19 13:52:15 +02:00
<MkSpacer :contentMax="700">
<MkHorizontalSwipe v-model:tab="tab" :tabs="headerTabs">
<div v-if="tab === 'my'" key="my" class="_gaps">
<MkButton primary rounded class="add" @click="create"><i class="ti ti-plus"></i> {{ i18n.ts.add }}</MkButton>
<MkPagination v-slot="{items}" ref="pagingComponent" :pagination="pagination" class="_gaps">
<MkA v-for="item in items" :key="item.id" :to="`/clips/${item.id}`">
<MkClipPreview :clip="item"/>
</MkA>
</MkPagination>
</div>
<div v-else-if="tab === 'favorites'" key="favorites" class="_gaps">
<MkA v-for="item in favorites" :key="item.id" :to="`/clips/${item.id}`">
2023-03-17 07:09:43 +01:00
<MkClipPreview :clip="item"/>
2022-07-20 15:24:26 +02:00
</MkA>
</div>
</MkHorizontalSwipe>
2022-07-20 15:24:26 +02:00
</MkSpacer>
</MkStickyContainer>
2020-11-15 04:04:54 +01:00
</template>
<script lang="ts" setup>
import { watch, ref, shallowRef, computed } from 'vue';
import * as Misskey from 'misskey-js';
import MkPagination from '@/components/MkPagination.vue';
import MkButton from '@/components/MkButton.vue';
2023-03-17 07:09:43 +01:00
import MkClipPreview from '@/components/MkClipPreview.vue';
2023-09-19 09:37:43 +02:00
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
2023-09-19 09:37:43 +02:00
import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { clipsCache } from '@/cache.js';
import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue';
2020-11-15 04:04:54 +01:00
const pagination = {
endpoint: 'clips/list' as const,
noPaging: true,
limit: 10,
};
2020-11-15 04:04:54 +01:00
const tab = ref('my');
const favorites = ref<Misskey.entities.Clip[] | null>(null);
2023-03-16 09:24:49 +01:00
const pagingComponent = shallowRef<InstanceType<typeof MkPagination>>();
2020-11-15 04:04:54 +01:00
watch(tab, async () => {
favorites.value = await misskeyApi('clips/my-favorites');
2023-03-16 09:24:49 +01:00
});
async function create() {
const { canceled, result } = await os.form(i18n.ts.createNewClip, {
name: {
type: 'string',
label: i18n.ts.name,
2020-11-15 04:04:54 +01:00
},
description: {
type: 'string',
required: false,
multiline: true,
treatAsMfm: true,
label: i18n.ts.description,
2020-11-15 04:04:54 +01:00
},
isPublic: {
type: 'boolean',
label: i18n.ts.public,
default: false,
},
});
if (canceled) return;
os.apiWithDialog('clips/create', result);
clipsCache.delete();
pagingComponent.value.reload();
}
function onClipCreated() {
pagingComponent.value.reload();
}
2020-11-15 04:04:54 +01:00
function onClipDeleted() {
pagingComponent.value.reload();
}
const headerActions = computed(() => []);
const headerTabs = computed(() => [{
2023-03-16 09:24:49 +01:00
key: 'my',
title: i18n.ts.myClips,
icon: 'ti ti-paperclip',
}, {
key: 'favorites',
title: i18n.ts.favorites,
icon: 'ti ti-heart',
}]);
definePageMetadata(() => ({
title: i18n.ts.clip,
icon: 'ti ti-paperclip',
}));
2020-11-15 04:04:54 +01:00
</script>
2020-11-15 04:34:47 +01:00
2023-03-16 09:24:49 +01:00
<style lang="scss" module>
</style>