summaryrefslogtreecommitdiff
path: root/packages/frontend/src/pages/clip.vue
blob: cd9cec0d4f16a26963257088e03eefac09721f4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<template>
<MkStickyContainer>
	<template #header><MkPageHeader :actions="headerActions"/></template>
	<MkSpacer :content-max="800">
		<div v-if="clip">
			<div class="okzinsic _panel">
				<div v-if="clip.description" class="description">
					<Mfm :text="clip.description" :is-note="false" :i="$i"/>
				</div>
				<div class="user">
					<MkAvatar :user="clip.user" class="avatar" indicator link preview/> <MkUserName :user="clip.user" :nowrap="false"/>
				</div>
			</div>

			<XNotes :pagination="pagination" :detail="true"/>
		</div>
	</MkSpacer>
</MkStickyContainer>
</template>

<script lang="ts" setup>
import { computed, watch, provide } from 'vue';
import * as misskey from 'misskey-js';
import XNotes from '@/components/MkNotes.vue';
import { $i } from '@/account';
import { i18n } from '@/i18n';
import * as os from '@/os';
import { definePageMetadata } from '@/scripts/page-metadata';

const props = defineProps<{
	clipId: string,
}>();

let clip: misskey.entities.Clip = $ref<misskey.entities.Clip>();
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,
	});
}, {
	immediate: true,
}); 

provide('currentClipPage', $$(clip));

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,
			},
			description: {
				type: 'string',
				required: false,
				multiline: true,
				label: i18n.ts.description,
				default: clip.description,
			},
			isPublic: {
				type: 'boolean',
				label: i18n.ts.public,
				default: clip.isPublic,
			},
		});
		if (canceled) return;

		os.apiWithDialog('clips/update', {
			clipId: clip.id,
			...result,
		});
	},
}, {
	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,
		});
	},
}] : null);

definePageMetadata(computed(() => clip ? {
	title: clip.name,
	icon: 'ti ti-paperclip',
} : null));
</script>

<style lang="scss" scoped>
.okzinsic {
	position: relative;
	margin-bottom: var(--margin);

	> .description {
		padding: 16px;
	}

	> .user {
		$height: 32px;
		padding: 16px;
		border-top: solid 0.5px var(--divider);
		line-height: $height;

		> .avatar {
			width: $height;
			height: $height;
		}
	}
}
</style>