egirlskey/packages/frontend/src/pages/clip.vue

182 lines
4.7 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
2020-11-15 03:34:47 +00:00
<template>
<MkStickyContainer>
<template #header><MkPageHeader :actions="headerActions"/></template>
2023-05-19 07:20:53 +00:00
<MkSpacer :contentMax="800">
2023-05-19 09:16:26 +00:00
<div v-if="clip" class="_gaps">
<div class="_panel">
<div v-if="clip.description" :class="$style.description">
<Mfm :text="clip.description" :isNote="false"/>
</div>
2023-09-30 19:53:52 +00:00
<MkButton v-if="favorited" v-tooltip="i18n.ts.unfavorite" asLike rounded primary @click="unfavorite()"><i class="ph-heart ph-bold ph-lg"></i><span v-if="clip.favoritedCount > 0" style="margin-left: 6px;">{{ clip.favoritedCount }}</span></MkButton>
<MkButton v-else v-tooltip="i18n.ts.favorite" asLike rounded @click="favorite()"><i class="ph-heart ph-bold ph-lg"></i><span v-if="clip.favoritedCount > 0" style="margin-left: 6px;">{{ clip.favoritedCount }}</span></MkButton>
2023-05-19 09:16:26 +00:00
<div :class="$style.user">
<MkAvatar :user="clip.user" :class="$style.avatar" indicator link preview/> <MkUserName :user="clip.user" :nowrap="false"/>
</div>
</div>
2020-11-15 03:34:47 +00:00
<MkNotes :pagination="pagination" :detail="true"/>
</div>
</MkSpacer>
</MkStickyContainer>
2020-11-15 03:34:47 +00:00
</template>
<script lang="ts" setup>
import { computed, watch, provide, ref } from 'vue';
import * as Misskey from 'misskey-js';
import MkNotes from '@/components/MkNotes.vue';
2023-09-19 07:37:43 +00:00
import { $i } from '@/account.js';
import { i18n } from '@/i18n.js';
import * as os from '@/os.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { url } from '@/config.js';
2023-03-16 08:24:49 +00:00
import MkButton from '@/components/MkButton.vue';
import { clipsCache } from '@/cache.js';
import { isSupportShare } from '@/scripts/navigator.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
2020-11-15 03:34:47 +00:00
const props = defineProps<{
clipId: string,
}>();
const clip = ref<Misskey.entities.Clip | null>(null);
const favorited = ref(false);
const pagination = {
endpoint: 'clips/notes' as const,
limit: 10,
params: computed(() => ({
clipId: props.clipId,
})),
};
const isOwned = computed<boolean | null>(() => $i && clip.value && ($i.id === clip.value.userId));
watch(() => props.clipId, async () => {
clip.value = await os.api('clips/show', {
clipId: props.clipId,
});
favorited.value = clip.value.isFavorited;
}, {
immediate: true,
});
provide('currentClip', clip);
2023-03-16 08:24:49 +00:00
function favorite() {
os.apiWithDialog('clips/favorite', {
clipId: props.clipId,
}).then(() => {
favorited.value = true;
2023-03-16 08:24:49 +00:00
});
}
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.value = false;
2023-03-16 08:24:49 +00:00
});
}
const headerActions = computed(() => clip.value && isOwned.value ? [{
2023-09-30 19:53:52 +00:00
icon: 'ph-pencil ph-bold ph-lg',
text: i18n.ts.edit,
handler: async (): Promise<void> => {
const { canceled, result } = await os.form(clip.value.name, {
name: {
type: 'string',
label: i18n.ts.name,
default: clip.value.name,
2020-11-15 03:34:47 +00:00
},
description: {
type: 'string',
required: false,
multiline: true,
treatAsMfm: true,
label: i18n.ts.description,
default: clip.value.description,
2020-11-15 03:34:47 +00:00
},
isPublic: {
type: 'boolean',
label: i18n.ts.public,
default: clip.value.isPublic,
},
});
if (canceled) return;
os.apiWithDialog('clips/update', {
clipId: clip.value.id,
...result,
});
clipsCache.delete();
},
}, ...(clip.value.isPublic ? [{
2023-12-23 01:09:23 +00:00
icon: 'ph-share-network ph-bold ph-lg',
text: i18n.ts.copyUrl,
handler: async (): Promise<void> => {
copyToClipboard(`${url}/clips/${clip.value.id}`);
os.success();
},
}] : []), ...(clip.value.isPublic && isSupportShare() ? [{
icon: 'ph-share-network ph-bold ph-lg',
text: i18n.ts.share,
handler: async (): Promise<void> => {
navigator.share({
title: clip.value.name,
text: clip.value.description,
url: `${url}/clips/${clip.value.id}`,
});
},
}] : []), {
2023-09-30 19:53:52 +00:00
icon: 'ph-trash ph-bold ph-lg',
text: i18n.ts.delete,
danger: true,
handler: async (): Promise<void> => {
const { canceled } = await os.confirm({
type: 'warning',
text: i18n.t('deleteAreYouSure', { x: clip.value.name }),
});
if (canceled) return;
await os.apiWithDialog('clips/delete', {
clipId: clip.value.id,
});
clipsCache.delete();
},
}] : null);
definePageMetadata(computed(() => clip.value ? {
title: clip.value.name,
2023-09-30 19:53:52 +00:00
icon: 'ph-paperclip ph-bold ph-lg',
} : null));
2020-11-15 03:34:47 +00:00
</script>
2023-05-19 09:16:26 +00:00
<style lang="scss" module>
.description {
padding: 16px;
}
.user {
--height: 32px;
padding: 16px;
border-top: solid 0.5px var(--divider);
line-height: var(--height);
}
.avatar {
width: var(--height);
height: var(--height);
2020-11-15 03:34:47 +00:00
}
</style>