2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
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">
|
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>
|
|
|
|
|
2022-01-15 08:40:15 +01:00
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { watch, ref, shallowRef, computed } from 'vue';
|
2023-12-26 06:19:35 +01:00
|
|
|
import * as Misskey from 'misskey-js';
|
2023-12-27 07:55:09 +01:00
|
|
|
import MkPagination from '@/components/MkPagination.vue';
|
2022-09-06 11:21:49 +02:00
|
|
|
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';
|
2024-01-04 10:32:46 +01:00
|
|
|
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';
|
2023-12-24 08:16:58 +01:00
|
|
|
import { clipsCache } from '@/cache.js';
|
2020-11-15 04:04:54 +01:00
|
|
|
|
2022-01-15 08:40:15 +01:00
|
|
|
const pagination = {
|
|
|
|
endpoint: 'clips/list' as const,
|
2023-04-09 01:03:29 +02:00
|
|
|
noPaging: true,
|
2022-01-15 08:40:15 +01:00
|
|
|
limit: 10,
|
2023-12-27 07:55:09 +01:00
|
|
|
};
|
2020-11-15 04:04:54 +01:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const tab = ref('my');
|
2023-12-26 06:19:35 +01:00
|
|
|
const favorites = ref<Misskey.entities.Clip[] | null>(null);
|
2023-03-16 09:24:49 +01:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const pagingComponent = shallowRef<InstanceType<typeof MkPagination>>();
|
2020-11-15 04:04:54 +01:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
watch(tab, async () => {
|
2024-01-04 10:32:46 +01:00
|
|
|
favorites.value = await misskeyApi('clips/my-favorites');
|
2023-03-16 09:24:49 +01:00
|
|
|
});
|
|
|
|
|
2022-01-15 08:40:15 +01:00
|
|
|
async function create() {
|
2022-01-28 03:39:49 +01:00
|
|
|
const { canceled, result } = await os.form(i18n.ts.createNewClip, {
|
2022-01-15 08:40:15 +01:00
|
|
|
name: {
|
|
|
|
type: 'string',
|
2022-01-28 03:39:49 +01:00
|
|
|
label: i18n.ts.name,
|
2020-11-15 04:04:54 +01:00
|
|
|
},
|
2022-01-15 08:40:15 +01:00
|
|
|
description: {
|
|
|
|
type: 'string',
|
|
|
|
required: false,
|
|
|
|
multiline: true,
|
2023-12-14 05:11:23 +01:00
|
|
|
treatAsMfm: true,
|
2022-01-28 03:39:49 +01:00
|
|
|
label: i18n.ts.description,
|
2020-11-15 04:04:54 +01:00
|
|
|
},
|
2022-01-15 08:40:15 +01:00
|
|
|
isPublic: {
|
|
|
|
type: 'boolean',
|
2022-01-28 03:39:49 +01:00
|
|
|
label: i18n.ts.public,
|
2022-01-15 08:40:15 +01:00
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
os.apiWithDialog('clips/create', result);
|
|
|
|
|
2023-03-24 08:54:37 +01:00
|
|
|
clipsCache.delete();
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
pagingComponent.value.reload();
|
2022-01-15 08:40:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function onClipCreated() {
|
2023-12-07 06:42:09 +01:00
|
|
|
pagingComponent.value.reload();
|
2022-01-15 08:40:15 +01:00
|
|
|
}
|
2020-11-15 04:04:54 +01:00
|
|
|
|
2022-01-15 08:40:15 +01:00
|
|
|
function onClipDeleted() {
|
2023-12-07 06:42:09 +01:00
|
|
|
pagingComponent.value.reload();
|
2022-01-15 08:40:15 +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-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',
|
|
|
|
}]);
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.clip,
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-paperclip',
|
2022-06-20 10:38:49 +02:00
|
|
|
action: {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-plus',
|
2022-06-20 10:38:49 +02:00
|
|
|
handler: create,
|
2022-01-15 08:40:15 +01:00
|
|
|
},
|
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>
|