2022-07-20 22:24:26 +09:00
|
|
|
<template>
|
|
|
|
<MkStickyContainer>
|
2023-03-16 17:24:49 +09:00
|
|
|
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
|
2022-07-20 22:24:26 +09:00
|
|
|
<MkSpacer :content-max="700">
|
2023-03-17 15:09:43 +09:00
|
|
|
<div v-if="tab === 'my'" class="_gaps">
|
2023-03-16 17:24:49 +09:00
|
|
|
<MkButton primary rounded class="add" @click="create"><i class="ti ti-plus"></i> {{ i18n.ts.add }}</MkButton>
|
2020-11-15 12:04:54 +09:00
|
|
|
|
2023-03-17 15:09:43 +09: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 22:24:26 +09:00
|
|
|
</MkA>
|
|
|
|
</MkPagination>
|
|
|
|
</div>
|
2023-03-16 17:24:49 +09:00
|
|
|
<div v-else-if="tab === 'favorites'" class="_gaps">
|
2023-03-17 15:09:43 +09:00
|
|
|
<MkA v-for="item in favorites" :key="item.id" :to="`/clips/${item.id}`">
|
|
|
|
<MkClipPreview :clip="item"/>
|
2023-03-16 17:24:49 +09:00
|
|
|
</MkA>
|
|
|
|
</div>
|
2022-07-20 22:24:26 +09:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-11-15 12:04:54 +09:00
|
|
|
</template>
|
|
|
|
|
2022-01-15 16:40:15 +09:00
|
|
|
<script lang="ts" setup>
|
2023-03-16 17:24:49 +09:00
|
|
|
import { watch } from 'vue';
|
2022-09-06 18:21:49 +09:00
|
|
|
import MkPagination from '@/components/MkPagination.vue';
|
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-03-17 15:09:43 +09:00
|
|
|
import MkClipPreview from '@/components/MkClipPreview.vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import * as os from '@/os';
|
2022-01-28 01:09:46 +09:00
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 17:38:49 +09:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2023-03-24 17:03:03 +09:00
|
|
|
import { clipsCache } from '@/cache';
|
2020-11-15 12:04:54 +09:00
|
|
|
|
2022-01-15 16:40:15 +09:00
|
|
|
const pagination = {
|
|
|
|
endpoint: 'clips/list' as const,
|
2023-04-09 08:03:29 +09:00
|
|
|
noPaging: true,
|
2022-01-15 16:40:15 +09:00
|
|
|
limit: 10,
|
|
|
|
};
|
2020-11-15 12:04:54 +09:00
|
|
|
|
2023-03-16 17:24:49 +09:00
|
|
|
let tab = $ref('my');
|
|
|
|
let favorites = $ref();
|
|
|
|
|
2023-01-03 13:37:32 +09:00
|
|
|
const pagingComponent = $shallowRef<InstanceType<typeof MkPagination>>();
|
2020-11-15 12:04:54 +09:00
|
|
|
|
2023-03-16 17:24:49 +09:00
|
|
|
watch($$(tab), async () => {
|
|
|
|
favorites = await os.api('clips/my-favorites');
|
|
|
|
});
|
|
|
|
|
2022-01-15 16:40:15 +09:00
|
|
|
async function create() {
|
2022-01-28 11:39:49 +09:00
|
|
|
const { canceled, result } = await os.form(i18n.ts.createNewClip, {
|
2022-01-15 16:40:15 +09:00
|
|
|
name: {
|
|
|
|
type: 'string',
|
2022-01-28 11:39:49 +09:00
|
|
|
label: i18n.ts.name,
|
2020-11-15 12:04:54 +09:00
|
|
|
},
|
2022-01-15 16:40:15 +09:00
|
|
|
description: {
|
|
|
|
type: 'string',
|
|
|
|
required: false,
|
|
|
|
multiline: true,
|
2022-01-28 11:39:49 +09:00
|
|
|
label: i18n.ts.description,
|
2020-11-15 12:04:54 +09:00
|
|
|
},
|
2022-01-15 16:40:15 +09:00
|
|
|
isPublic: {
|
|
|
|
type: 'boolean',
|
2022-01-28 11:39:49 +09:00
|
|
|
label: i18n.ts.public,
|
2022-01-15 16:40:15 +09:00
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
os.apiWithDialog('clips/create', result);
|
|
|
|
|
2023-03-24 16:54:37 +09:00
|
|
|
clipsCache.delete();
|
|
|
|
|
2022-01-15 16:40:15 +09:00
|
|
|
pagingComponent.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onClipCreated() {
|
|
|
|
pagingComponent.reload();
|
|
|
|
}
|
2020-11-15 12:04:54 +09:00
|
|
|
|
2022-01-15 16:40:15 +09:00
|
|
|
function onClipDeleted() {
|
|
|
|
pagingComponent.reload();
|
|
|
|
}
|
|
|
|
|
2022-06-20 17:38:49 +09:00
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
2023-03-16 17:24:49 +09:00
|
|
|
const headerTabs = $computed(() => [{
|
|
|
|
key: 'my',
|
|
|
|
title: i18n.ts.myClips,
|
|
|
|
icon: 'ti ti-paperclip',
|
|
|
|
}, {
|
|
|
|
key: 'favorites',
|
|
|
|
title: i18n.ts.favorites,
|
|
|
|
icon: 'ti ti-heart',
|
|
|
|
}]);
|
2022-06-20 17:38:49 +09:00
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.clip,
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-paperclip',
|
2022-06-20 17:38:49 +09:00
|
|
|
action: {
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-plus',
|
2022-06-20 17:38:49 +09:00
|
|
|
handler: create,
|
2022-01-15 16:40:15 +09:00
|
|
|
},
|
2020-11-15 12:04:54 +09:00
|
|
|
});
|
|
|
|
</script>
|
2020-11-15 12:34:47 +09:00
|
|
|
|
2023-03-16 17:24:49 +09:00
|
|
|
<style lang="scss" module>
|
|
|
|
|
|
|
|
</style>
|