hippofish/packages/client/src/pages/clip.vue

164 lines
3.3 KiB
Vue
Raw Normal View History

2020-11-15 04:34:47 +01:00
<template>
2023-04-08 02:01:42 +02:00
<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"
:show-indicator="true"
/>
<MkUserName :user="clip.user" :nowrap="false" />
</div>
</div>
2020-11-15 04:34:47 +01:00
2023-04-08 02:01:42 +02:00
<XNotes :pagination="pagination" :detail="true" />
</div>
</MkSpacer>
</MkStickyContainer>
2020-11-15 04:34:47 +01:00
</template>
<script lang="ts" setup>
2023-09-02 01:27:33 +02:00
import { computed, provide, ref, watch } from "vue";
2023-09-24 06:27:16 +02:00
import type * as firefish from "firefish-js";
2023-04-08 02:01:42 +02:00
import XNotes from "@/components/MkNotes.vue";
import { $i } from "@/reactiveAccount";
2023-04-08 02:01:42 +02:00
import { i18n } from "@/i18n";
import * as os from "@/os";
import { definePageMetadata } from "@/scripts/page-metadata";
import icon from "@/scripts/icon";
2020-11-15 04:34:47 +01:00
const props = defineProps<{
2023-04-08 02:01:42 +02:00
clipId: string;
}>();
2023-09-24 06:27:16 +02:00
const clip = ref<firefish.entities.Clip>();
const pagination = {
2023-04-08 02:01:42 +02:00
endpoint: "clips/notes" as const,
limit: 10,
params: computed(() => ({
clipId: props.clipId,
})),
};
const isOwned: boolean | null = computed<boolean | null>(
() => $i && clip.value && $i.id === clip.value.userId,
2023-04-08 02:01:42 +02:00
);
2023-04-08 02:01:42 +02:00
watch(
() => props.clipId,
async () => {
clip.value = await os.api("clips/show", {
2023-04-08 02:01:42 +02:00
clipId: props.clipId,
});
},
{
immediate: true,
2023-07-06 03:28:27 +02:00
},
2023-04-08 02:01:42 +02:00
);
provide("currentClipPage", clip);
const headerActions = computed(() =>
clip.value && isOwned.value
2023-04-08 02:01:42 +02:00
? [
{
icon: `${icon("ph-pencil")}`,
2023-04-08 02:01:42 +02:00
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,
},
description: {
type: "string",
required: false,
multiline: true,
label: i18n.ts.description,
default: clip.value.description,
},
isPublic: {
type: "boolean",
label: i18n.ts.public,
default: clip.value.isPublic,
},
2023-04-08 02:01:42 +02:00
},
);
2023-04-08 02:01:42 +02:00
if (canceled) return;
2023-04-08 02:01:42 +02:00
os.apiWithDialog("clips/update", {
clipId: clip.value.id,
2023-04-08 02:01:42 +02:00
...result,
});
},
},
{
icon: `${icon("ph-trash")}`,
2023-04-08 02:01:42 +02:00
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,
}),
2023-04-08 02:01:42 +02:00
});
if (canceled) return;
2023-04-08 02:01:42 +02:00
await os.apiWithDialog("clips/delete", {
clipId: clip.value.id,
2023-04-08 02:01:42 +02:00
});
},
},
]
2023-07-06 03:28:27 +02:00
: null,
2023-04-08 02:01:42 +02:00
);
2023-04-08 02:01:42 +02:00
definePageMetadata(
computed(() =>
clip.value
2023-04-08 02:01:42 +02:00
? {
title: clip.value.name,
icon: `${icon("ph-paperclip")}`,
2023-04-08 02:01:42 +02:00
}
2023-07-06 03:28:27 +02:00
: null,
),
2023-04-08 02:01:42 +02:00
);
2020-11-15 04:34:47 +01:00
</script>
<style lang="scss" scoped>
.okzinsic {
position: relative;
margin-bottom: var(--margin);
2020-11-15 04:34:47 +01:00
> .description {
padding: 16px;
}
2020-11-15 04:47:54 +01:00
> .user {
$height: 32px;
padding: 16px;
border-top: solid 0.5px var(--divider);
2020-11-15 04:47:54 +01:00
line-height: $height;
> .avatar {
width: $height;
height: $height;
}
}
2020-11-15 04:34:47 +01:00
}
</style>