1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<PageWithHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs" :swipable="true">
<div class="_spacer _gaps" style="--MI_SPACER-w: 700px;">
<MkTip k="clips">
{{ i18n.ts._clip.tip }}
</MkTip>
<div v-if="tab === '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" withControl>
<MkClipPreview v-for="item in items" :key="item.id" :clip="item" :noUserInfo="true"/>
</MkPagination>
</div>
<div v-else-if="tab === 'favorites'" class="_gaps">
<MkClipPreview v-for="item in favorites" :key="item.id" :clip="item"/>
</div>
</div>
</PageWithHeader>
</template>
<script lang="ts" setup>
import { watch, ref, useTemplateRef, computed } from 'vue';
import * as Misskey from 'misskey-js';
import MkPagination from '@/components/MkPagination.vue';
import MkButton from '@/components/MkButton.vue';
import MkClipPreview from '@/components/MkClipPreview.vue';
import * as os from '@/os.js';
import { misskeyApi } from '@/utility/misskey-api.js';
import { i18n } from '@/i18n.js';
import { definePage } from '@/page.js';
import { clipsCache } from '@/cache.js';
const pagination = {
endpoint: 'clips/list' as const,
noPaging: true,
limit: 10,
};
const tab = ref('my');
const favorites = ref<Misskey.entities.Clip[] | null>(null);
const pagingComponent = useTemplateRef('pagingComponent');
watch(tab, async () => {
favorites.value = await misskeyApi('clips/my-favorites');
});
async function create() {
const { canceled, result } = await os.form(i18n.ts.createNewClip, {
name: {
type: 'string',
label: i18n.ts.name,
},
description: {
type: 'string',
required: false,
multiline: true,
treatAsMfm: true,
label: i18n.ts.description,
},
isPublic: {
type: 'boolean',
label: i18n.ts.public,
default: false,
},
});
if (canceled) return;
os.apiWithDialog('clips/create', result);
clipsCache.delete();
pagingComponent.value?.paginator.reload();
}
function onClipCreated() {
pagingComponent.value?.paginator.reload();
}
function onClipDeleted() {
pagingComponent.value?.paginator.reload();
}
const headerActions = computed(() => []);
const headerTabs = computed(() => [{
key: 'my',
title: i18n.ts.myClips,
icon: 'ti ti-paperclip',
}, {
key: 'favorites',
title: i18n.ts.favorites,
icon: 'ti ti-heart',
}]);
definePage(() => ({
title: i18n.ts.clip,
icon: 'ti ti-paperclip',
}));
</script>
<style lang="scss" module>
</style>
|