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

107 lines
2.4 KiB
Vue
Raw Normal View History

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>
2022-07-20 15:24:26 +02:00
<MkSpacer :content-max="700">
2023-03-17 07:09:43 +01:00
<div v-if="tab === 'my'" class="_gaps">
2023-03-16 09:24:49 +01:00
<MkButton primary rounded class="add" @click="create"><i class="ti ti-plus"></i> {{ i18n.ts.add }}</MkButton>
2020-11-15 04:04:54 +01:00
2023-03-17 07:09:43 +01:00
<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"/>
2022-07-20 15:24:26 +02:00
</MkA>
</MkPagination>
</div>
2023-03-16 09:24:49 +01:00
<div v-else-if="tab === 'favorites'" class="_gaps">
2023-03-17 07:09:43 +01:00
<MkA v-for="item in favorites" :key="item.id" :to="`/clips/${item.id}`">
<MkClipPreview :clip="item"/>
2023-03-16 09:24:49 +01:00
</MkA>
</div>
2022-07-20 15:24:26 +02:00
</MkSpacer>
</MkStickyContainer>
2020-11-15 04:04:54 +01:00
</template>
<script lang="ts" setup>
2023-03-16 09:24:49 +01:00
import { watch } from 'vue';
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';
2021-11-11 18:02:25 +01:00
import * as os from '@/os';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';
2023-03-24 09:03:03 +01:00
import { clipsCache } from '@/cache';
2020-11-15 04:04:54 +01:00
const pagination = {
endpoint: 'clips/list' as const,
limit: 10,
};
2020-11-15 04:04:54 +01:00
2023-03-16 09:24:49 +01:00
let tab = $ref('my');
let favorites = $ref();
const pagingComponent = $shallowRef<InstanceType<typeof MkPagination>>();
2020-11-15 04:04:54 +01:00
2023-03-16 09:24:49 +01:00
watch($$(tab), async () => {
favorites = await os.api('clips/my-favorites');
});
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,
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.reload();
}
function onClipCreated() {
pagingComponent.reload();
}
2020-11-15 04:04:54 +01:00
function onClipDeleted() {
pagingComponent.reload();
}
const headerActions = $computed(() => []);
2023-03-16 09:24:49 +01:00
const headerTabs = $computed(() => [{
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',
action: {
icon: 'ti ti-plus',
handler: create,
},
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>