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-16 09:24:49 +01:00
|
|
|
<div v-if="tab === 'my'" class="qtcaoidl">
|
|
|
|
<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
|
|
|
|
2022-07-20 15:24:26 +02:00
|
|
|
<MkPagination v-slot="{items}" ref="pagingComponent" :pagination="pagination" class="list">
|
2023-01-05 13:04:56 +01:00
|
|
|
<MkA v-for="item in items" :key="item.id" :to="`/clips/${item.id}`" class="item _panel _margin">
|
2022-07-20 15:24:26 +02:00
|
|
|
<b>{{ item.name }}</b>
|
|
|
|
<div v-if="item.description" class="description">{{ item.description }}</div>
|
|
|
|
</MkA>
|
|
|
|
</MkPagination>
|
|
|
|
</div>
|
2023-03-16 09:24:49 +01:00
|
|
|
<div v-else-if="tab === 'favorites'" class="_gaps">
|
|
|
|
<MkA v-for="item in favorites" :key="item.id" :to="`/clips/${item.id}`" :class="$style.clip" class="_panel">
|
|
|
|
<b>{{ item.name }}</b>
|
|
|
|
<div v-if="item.description" :class="$style.clipDescription">{{ item.description }}</div>
|
|
|
|
<div v-if="item.lastClippedAt">{{ i18n.ts.updatedAt }}: <MkTime :time="item.lastClippedAt" mode="detail"/></div>
|
|
|
|
<div :class="$style.clipUser">
|
|
|
|
<MkAvatar :user="item.user" :class="$style.clipUserAvatar" indicator link preview/> <MkUserName :user="item.user" :nowrap="false"/>
|
|
|
|
</div>
|
|
|
|
</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-03-16 09:24:49 +01:00
|
|
|
import { watch } from 'vue';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkPagination from '@/components/MkPagination.vue';
|
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import * as os from '@/os';
|
2022-01-27 17:09:46 +01:00
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 10:38:49 +02:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2020-11-15 04:04:54 +01:00
|
|
|
|
2022-01-15 08:40:15 +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();
|
|
|
|
|
2023-01-03 05:37:32 +01:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
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,
|
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);
|
|
|
|
|
|
|
|
pagingComponent.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onClipCreated() {
|
|
|
|
pagingComponent.reload();
|
|
|
|
}
|
2020-11-15 04:04:54 +01:00
|
|
|
|
2022-01-15 08:40:15 +01:00
|
|
|
function onClipDeleted() {
|
|
|
|
pagingComponent.reload();
|
|
|
|
}
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
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',
|
|
|
|
}]);
|
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
|
|
|
|
2022-12-27 10:29:39 +01:00
|
|
|
<style lang="scss" scoped>
|
2020-11-15 04:34:47 +01:00
|
|
|
.qtcaoidl {
|
|
|
|
> .add {
|
|
|
|
margin: 0 auto 16px auto;
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:09:12 +01:00
|
|
|
> .list {
|
|
|
|
> .item {
|
|
|
|
display: block;
|
|
|
|
padding: 16px;
|
2020-11-15 04:34:47 +01:00
|
|
|
|
2021-12-02 12:09:12 +01:00
|
|
|
> .description {
|
|
|
|
margin-top: 8px;
|
|
|
|
padding-top: 8px;
|
|
|
|
border-top: solid 0.5px var(--divider);
|
2020-11-15 04:34:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
2023-03-16 09:24:49 +01:00
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.clip {
|
|
|
|
display: block;
|
|
|
|
padding: 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.clipDescription {
|
|
|
|
padding: 8px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.clipUser {
|
|
|
|
padding-top: 16px;
|
|
|
|
border-top: solid 0.5px var(--divider);
|
|
|
|
}
|
|
|
|
|
|
|
|
.clipUserAvatar {
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
}
|
|
|
|
</style>
|