1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-17 08:09:14 +09:00
cherrypick/packages/frontend/src/pages/clip.vue

172 lines
4.1 KiB
Vue
Raw Normal View History

2020-11-15 12:34:47 +09:00
<template>
<MkStickyContainer>
<template #header><MkPageHeader :actions="headerActions"/></template>
2023-05-19 16:20:53 +09:00
<MkSpacer :contentMax="800">
<div v-if="clip">
<div class="okzinsic _panel">
<div v-if="clip.description" class="description">
<Mfm :text="clip.description" :isNote="false" :i="$i"/>
</div>
2023-05-19 16:20:53 +09:00
<MkButton v-if="favorited" v-tooltip="i18n.ts.unfavorite" asLike class="button" rounded primary @click="unfavorite()"><i class="ti ti-heart"></i><span v-if="clip.favoritedCount > 0" style="margin-left: 6px;">{{ clip.favoritedCount }}</span></MkButton>
<MkButton v-else v-tooltip="i18n.ts.favorite" asLike class="button" rounded @click="favorite()"><i class="ti ti-heart"></i><span v-if="clip.favoritedCount > 0" style="margin-left: 6px;">{{ clip.favoritedCount }}</span></MkButton>
<div class="user">
2023-02-08 20:07:19 +09:00
<MkAvatar :user="clip.user" class="avatar" indicator link preview/> <MkUserName :user="clip.user" :nowrap="false"/>
</div>
</div>
2020-11-15 12:34:47 +09:00
<MkNotes :pagination="pagination" :detail="true"/>
</div>
</MkSpacer>
</MkStickyContainer>
2020-11-15 12:34:47 +09:00
</template>
<script lang="ts" setup>
import { computed, watch, provide } from 'vue';
import * as misskey from 'misskey-js';
import MkNotes from '@/components/MkNotes.vue';
import { $i } from '@/account';
import { i18n } from '@/i18n';
2021-11-12 02:02:25 +09:00
import * as os from '@/os';
import { definePageMetadata } from '@/scripts/page-metadata';
import { url } from '@/config';
2023-03-16 17:24:49 +09:00
import MkButton from '@/components/MkButton.vue';
import { clipsCache } from '@/cache';
2020-11-15 12:34:47 +09:00
const props = defineProps<{
clipId: string,
}>();
let clip: misskey.entities.Clip = $ref<misskey.entities.Clip>();
2023-03-16 17:24:49 +09:00
let favorited = $ref(false);
const pagination = {
endpoint: 'clips/notes' as const,
limit: 10,
params: computed(() => ({
clipId: props.clipId,
})),
};
const isOwned: boolean | null = $computed<boolean | null>(() => $i && clip && ($i.id === clip.userId));
watch(() => props.clipId, async () => {
clip = await os.api('clips/show', {
clipId: props.clipId,
});
2023-03-16 17:24:49 +09:00
favorited = clip.isFavorited;
}, {
immediate: true,
});
provide('currentClip', $$(clip));
2023-03-16 17:24:49 +09:00
function favorite() {
os.apiWithDialog('clips/favorite', {
clipId: props.clipId,
}).then(() => {
favorited = true;
});
}
async function unfavorite() {
const confirm = await os.confirm({
type: 'warning',
text: i18n.ts.unfavoriteConfirm,
});
if (confirm.canceled) return;
os.apiWithDialog('clips/unfavorite', {
clipId: props.clipId,
}).then(() => {
favorited = false;
});
}
const headerActions = $computed(() => clip && isOwned ? [{
icon: 'ti ti-pencil',
text: i18n.ts.edit,
handler: async (): Promise<void> => {
const { canceled, result } = await os.form(clip.name, {
name: {
type: 'string',
label: i18n.ts.name,
default: clip.name,
2020-11-15 12:34:47 +09:00
},
description: {
type: 'string',
required: false,
multiline: true,
label: i18n.ts.description,
default: clip.description,
2020-11-15 12:34:47 +09:00
},
isPublic: {
type: 'boolean',
label: i18n.ts.public,
default: clip.isPublic,
},
});
if (canceled) return;
os.apiWithDialog('clips/update', {
clipId: clip.id,
...result,
});
clipsCache.delete();
},
}, ...(clip.isPublic ? [{
icon: 'ti ti-share',
text: i18n.ts.share,
handler: async (): Promise<void> => {
navigator.share({
title: clip.name,
text: clip.description,
url: `${url}/clips/${clip.id}`,
});
},
}] : []), {
icon: 'ti ti-trash',
text: i18n.ts.delete,
danger: true,
handler: async (): Promise<void> => {
const { canceled } = await os.confirm({
type: 'warning',
text: i18n.t('deleteAreYouSure', { x: clip.name }),
});
if (canceled) return;
await os.apiWithDialog('clips/delete', {
clipId: clip.id,
});
clipsCache.delete();
},
}] : null);
definePageMetadata(computed(() => clip ? {
title: clip.name,
icon: 'ti ti-paperclip',
} : null));
2020-11-15 12:34:47 +09:00
</script>
<style lang="scss" scoped>
2020-11-15 12:34:47 +09:00
.okzinsic {
position: relative;
margin-bottom: var(--margin);
2020-11-15 12:34:47 +09:00
> .description {
padding: 16px;
}
2020-11-15 12:47:54 +09:00
> .user {
$height: 32px;
padding: 16px;
border-top: solid 0.5px var(--divider);
2020-11-15 12:47:54 +09:00
line-height: $height;
> .avatar {
width: $height;
height: $height;
}
}
2020-11-15 12:34:47 +09:00
}
</style>