2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-11-15 04:34:47 +01:00
|
|
|
<template>
|
2022-06-20 10:38:49 +02:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader :actions="headerActions"/></template>
|
2023-05-19 09:20:53 +02:00
|
|
|
<MkSpacer :contentMax="800">
|
2023-05-19 11:16:26 +02:00
|
|
|
<div v-if="clip" class="_gaps">
|
|
|
|
<div class="_panel">
|
|
|
|
<div v-if="clip.description" :class="$style.description">
|
2023-11-04 10:27:22 +01:00
|
|
|
<Mfm :text="clip.description" :isNote="false"/>
|
2022-06-20 10:38:49 +02:00
|
|
|
</div>
|
2023-05-19 11:16:26 +02:00
|
|
|
<MkButton v-if="favorited" v-tooltip="i18n.ts.unfavorite" asLike 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 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="$style.user">
|
|
|
|
<MkAvatar :user="clip.user" :class="$style.avatar" indicator link preview/> <MkUserName :user="clip.user" :nowrap="false"/>
|
2022-06-20 10:38:49 +02:00
|
|
|
</div>
|
2021-12-10 08:15:36 +01:00
|
|
|
</div>
|
2020-11-15 04:34:47 +01:00
|
|
|
|
2023-02-22 03:00:34 +01:00
|
|
|
<MkNotes :pagination="pagination" :detail="true"/>
|
2022-06-20 10:38:49 +02:00
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-11-15 04:34:47 +01:00
|
|
|
</template>
|
|
|
|
|
2022-06-18 11:23:54 +02:00
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { computed, watch, provide, ref } from 'vue';
|
2023-09-04 06:33:38 +02:00
|
|
|
import * as Misskey from 'misskey-js';
|
2023-02-22 03:00:34 +01:00
|
|
|
import MkNotes from '@/components/MkNotes.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { $i } from '@/account.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import * as os from '@/os.js';
|
2024-01-04 10:32:46 +01:00
|
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
|
|
|
import { url } from '@/config.js';
|
2023-03-16 09:24:49 +01:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-12-24 08:16:58 +01:00
|
|
|
import { clipsCache } from '@/cache.js';
|
2023-11-30 00:15:13 +01:00
|
|
|
import { isSupportShare } from '@/scripts/navigator.js';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
|
2020-11-15 04:34:47 +01:00
|
|
|
|
2022-06-18 11:23:54 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
clipId: string,
|
|
|
|
}>();
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const clip = ref<Misskey.entities.Clip | null>(null);
|
|
|
|
const favorited = ref(false);
|
2022-06-18 11:23:54 +02:00
|
|
|
const pagination = {
|
|
|
|
endpoint: 'clips/notes' as const,
|
|
|
|
limit: 10,
|
|
|
|
params: computed(() => ({
|
|
|
|
clipId: props.clipId,
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const isOwned = computed<boolean | null>(() => $i && clip.value && ($i.id === clip.value.userId));
|
2022-06-18 11:23:54 +02:00
|
|
|
|
|
|
|
watch(() => props.clipId, async () => {
|
2024-01-04 10:32:46 +01:00
|
|
|
clip.value = await misskeyApi('clips/show', {
|
2022-06-18 11:23:54 +02:00
|
|
|
clipId: props.clipId,
|
|
|
|
});
|
2023-12-07 06:42:09 +01:00
|
|
|
favorited.value = clip.value.isFavorited;
|
2022-06-18 11:23:54 +02:00
|
|
|
}, {
|
|
|
|
immediate: true,
|
2023-07-08 00:08:16 +02:00
|
|
|
});
|
2022-06-18 11:23:54 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
provide('currentClip', clip);
|
2022-06-18 11:27:09 +02:00
|
|
|
|
2023-03-16 09:24:49 +01:00
|
|
|
function favorite() {
|
|
|
|
os.apiWithDialog('clips/favorite', {
|
|
|
|
clipId: props.clipId,
|
|
|
|
}).then(() => {
|
2023-12-07 06:42:09 +01:00
|
|
|
favorited.value = true;
|
2023-03-16 09:24:49 +01: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(() => {
|
2023-12-07 06:42:09 +01:00
|
|
|
favorited.value = false;
|
2023-03-16 09:24:49 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const headerActions = computed(() => clip.value && isOwned.value ? [{
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-pencil',
|
2022-06-20 10:38:49 +02:00
|
|
|
text: i18n.ts.edit,
|
|
|
|
handler: async (): Promise<void> => {
|
2023-12-07 06:42:09 +01:00
|
|
|
const { canceled, result } = await os.form(clip.value.name, {
|
2022-06-20 10:38:49 +02:00
|
|
|
name: {
|
|
|
|
type: 'string',
|
|
|
|
label: i18n.ts.name,
|
2023-12-07 06:42:09 +01:00
|
|
|
default: clip.value.name,
|
2020-11-15 04:34:47 +01:00
|
|
|
},
|
2022-06-20 10:38:49 +02:00
|
|
|
description: {
|
|
|
|
type: 'string',
|
|
|
|
required: false,
|
|
|
|
multiline: true,
|
2023-12-14 05:11:23 +01:00
|
|
|
treatAsMfm: true,
|
2022-06-20 10:38:49 +02:00
|
|
|
label: i18n.ts.description,
|
2023-12-07 06:42:09 +01:00
|
|
|
default: clip.value.description,
|
2020-11-15 04:34:47 +01:00
|
|
|
},
|
2022-06-20 10:38:49 +02:00
|
|
|
isPublic: {
|
|
|
|
type: 'boolean',
|
|
|
|
label: i18n.ts.public,
|
2023-12-07 06:42:09 +01:00
|
|
|
default: clip.value.isPublic,
|
2022-06-20 10:38:49 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
os.apiWithDialog('clips/update', {
|
2023-12-07 06:42:09 +01:00
|
|
|
clipId: clip.value.id,
|
2022-06-20 10:38:49 +02:00
|
|
|
...result,
|
|
|
|
});
|
2023-03-24 08:54:37 +01:00
|
|
|
|
|
|
|
clipsCache.delete();
|
2022-06-20 10:38:49 +02:00
|
|
|
},
|
2023-12-07 06:42:09 +01:00
|
|
|
}, ...(clip.value.isPublic ? [{
|
2023-11-30 00:15:13 +01:00
|
|
|
icon: 'ti ti-link',
|
|
|
|
text: i18n.ts.copyUrl,
|
|
|
|
handler: async (): Promise<void> => {
|
2023-12-07 06:42:09 +01:00
|
|
|
copyToClipboard(`${url}/clips/${clip.value.id}`);
|
2023-11-30 00:15:13 +01:00
|
|
|
os.success();
|
|
|
|
},
|
2023-12-07 06:42:09 +01:00
|
|
|
}] : []), ...(clip.value.isPublic && isSupportShare() ? [{
|
2023-03-04 02:17:45 +01:00
|
|
|
icon: 'ti ti-share',
|
|
|
|
text: i18n.ts.share,
|
|
|
|
handler: async (): Promise<void> => {
|
|
|
|
navigator.share({
|
2023-12-07 06:42:09 +01:00
|
|
|
title: clip.value.name,
|
|
|
|
text: clip.value.description,
|
|
|
|
url: `${url}/clips/${clip.value.id}`,
|
2023-03-04 02:17:45 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
}] : []), {
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-trash',
|
2022-06-20 10:38:49 +02:00
|
|
|
text: i18n.ts.delete,
|
|
|
|
danger: true,
|
|
|
|
handler: async (): Promise<void> => {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
2024-01-20 00:11:59 +01:00
|
|
|
text: i18n.tsx.deleteAreYouSure({ x: clip.value.name }),
|
2022-06-20 10:38:49 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
await os.apiWithDialog('clips/delete', {
|
2023-12-07 06:42:09 +01:00
|
|
|
clipId: clip.value.id,
|
2022-06-20 10:38:49 +02:00
|
|
|
});
|
2023-03-24 08:54:37 +01:00
|
|
|
|
|
|
|
clipsCache.delete();
|
2022-06-20 10:38:49 +02:00
|
|
|
},
|
|
|
|
}] : null);
|
|
|
|
|
2024-02-16 08:17:09 +01:00
|
|
|
definePageMetadata(() => ({
|
|
|
|
title: clip.value ? clip.value.name : i18n.ts.clip,
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-paperclip',
|
2024-02-16 08:17:09 +01:00
|
|
|
}));
|
2020-11-15 04:34:47 +01:00
|
|
|
</script>
|
|
|
|
|
2023-05-19 11:16:26 +02: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 04:34:47 +01:00
|
|
|
}
|
|
|
|
</style>
|