2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2021-04-26 04:10:45 +02:00
|
|
|
<template>
|
2022-06-30 14:38:34 +02:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
2023-05-29 10:13:12 +02:00
|
|
|
<MkSpacer :contentMax="800" :marginMin="16" :marginMax="32">
|
2023-05-07 20:36:48 +02:00
|
|
|
<FormSuspense :p="init" class="_gaps">
|
2023-01-07 07:09:46 +01:00
|
|
|
<MkInput v-model="title">
|
2022-07-20 15:24:26 +02:00
|
|
|
<template #label>{{ i18n.ts.title }}</template>
|
2023-01-07 07:09:46 +01:00
|
|
|
</MkInput>
|
2022-06-30 14:38:34 +02:00
|
|
|
|
2023-01-07 07:09:46 +01:00
|
|
|
<MkTextarea v-model="description" :max="500">
|
2022-07-20 15:24:26 +02:00
|
|
|
<template #label>{{ i18n.ts.description }}</template>
|
2023-01-07 07:09:46 +01:00
|
|
|
</MkTextarea>
|
2022-06-30 14:38:34 +02:00
|
|
|
|
2023-05-07 20:36:48 +02:00
|
|
|
<div class="_gaps_s">
|
2022-06-30 14:38:34 +02:00
|
|
|
<div v-for="file in files" :key="file.id" class="wqugxsfx" :style="{ backgroundImage: file ? `url(${ file.thumbnailUrl })` : null }">
|
|
|
|
<div class="name">{{ file.name }}</div>
|
2022-12-19 11:01:30 +01:00
|
|
|
<button v-tooltip="i18n.ts.remove" class="remove _button" @click="remove(file)"><i class="ti ti-x"></i></button>
|
2022-06-30 14:38:34 +02:00
|
|
|
</div>
|
2023-01-06 01:41:14 +01:00
|
|
|
<MkButton primary @click="selectFile"><i class="ti ti-plus"></i> {{ i18n.ts.attachFile }}</MkButton>
|
2021-04-26 04:10:45 +02:00
|
|
|
</div>
|
|
|
|
|
2023-01-07 06:59:54 +01:00
|
|
|
<MkSwitch v-model="isSensitive">{{ i18n.ts.markAsSensitive }}</MkSwitch>
|
2021-04-26 04:10:45 +02:00
|
|
|
|
2023-05-07 20:36:48 +02:00
|
|
|
<div class="_buttons">
|
|
|
|
<MkButton v-if="postId" primary @click="save"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>
|
|
|
|
<MkButton v-else primary @click="save"><i class="ti ti-device-floppy"></i> {{ i18n.ts.publish }}</MkButton>
|
2021-04-26 04:10:45 +02:00
|
|
|
|
2023-05-07 20:36:48 +02:00
|
|
|
<MkButton v-if="postId" danger @click="del"><i class="ti ti-trash"></i> {{ i18n.ts.delete }}</MkButton>
|
|
|
|
</div>
|
2022-06-30 14:38:34 +02:00
|
|
|
</FormSuspense>
|
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2021-04-26 04:10:45 +02:00
|
|
|
</template>
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { computed, watch, ref } from 'vue';
|
2023-12-26 06:19:35 +01:00
|
|
|
import * as Misskey from 'misskey-js';
|
2023-01-06 01:41:14 +01:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-01-07 07:09:46 +01:00
|
|
|
import MkInput from '@/components/MkInput.vue';
|
|
|
|
import MkTextarea from '@/components/MkTextarea.vue';
|
2023-01-07 06:59:54 +01:00
|
|
|
import MkSwitch from '@/components/MkSwitch.vue';
|
2022-01-04 14:42:04 +01:00
|
|
|
import FormSuspense from '@/components/form/suspense.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { selectFiles } from '@/scripts/select-file.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 { useRouter } from '@/router.js';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
postId?: string;
|
|
|
|
}>();
|
|
|
|
|
2023-12-26 06:19:35 +01:00
|
|
|
const init = ref<(() => Promise<any>) | null>(null);
|
|
|
|
const files = ref<Misskey.entities.DriveFile[]>([]);
|
|
|
|
const description = ref<string | null>(null);
|
|
|
|
const title = ref<string | null>(null);
|
2023-12-07 06:42:09 +01:00
|
|
|
const isSensitive = ref(false);
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
function selectFile(evt) {
|
|
|
|
selectFiles(evt.currentTarget ?? evt.target, null).then(selected => {
|
2023-12-07 06:42:09 +01:00
|
|
|
files.value = files.value.concat(selected);
|
2022-06-20 10:38:49 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove(file) {
|
2023-12-07 06:42:09 +01:00
|
|
|
files.value = files.value.filter(f => f.id !== file.id);
|
2022-06-20 10:38:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function save() {
|
|
|
|
if (props.postId) {
|
|
|
|
await os.apiWithDialog('gallery/posts/update', {
|
|
|
|
postId: props.postId,
|
2023-12-07 06:42:09 +01:00
|
|
|
title: title.value,
|
|
|
|
description: description.value,
|
|
|
|
fileIds: files.value.map(file => file.id),
|
|
|
|
isSensitive: isSensitive.value,
|
2022-06-20 10:38:49 +02:00
|
|
|
});
|
2022-06-30 14:38:34 +02:00
|
|
|
router.push(`/gallery/${props.postId}`);
|
2022-06-20 10:38:49 +02:00
|
|
|
} else {
|
|
|
|
const created = await os.apiWithDialog('gallery/posts/create', {
|
2023-12-07 06:42:09 +01:00
|
|
|
title: title.value,
|
|
|
|
description: description.value,
|
|
|
|
fileIds: files.value.map(file => file.id),
|
|
|
|
isSensitive: isSensitive.value,
|
2022-06-20 10:38:49 +02:00
|
|
|
});
|
|
|
|
router.push(`/gallery/${created.id}`);
|
2021-04-26 04:10:45 +02:00
|
|
|
}
|
2022-06-20 10:38:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function del() {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.ts.deleteConfirm,
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
await os.apiWithDialog('gallery/posts/delete', {
|
|
|
|
postId: props.postId,
|
|
|
|
});
|
2022-06-30 14:38:34 +02:00
|
|
|
router.push('/gallery');
|
2022-06-20 10:38:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
watch(() => props.postId, () => {
|
2024-01-04 10:32:46 +01:00
|
|
|
init.value = () => props.postId ? misskeyApi('gallery/posts/show', {
|
2022-06-20 10:38:49 +02:00
|
|
|
postId: props.postId,
|
|
|
|
}).then(post => {
|
2023-12-26 06:19:35 +01:00
|
|
|
files.value = post.files ?? [];
|
2023-12-07 06:42:09 +01:00
|
|
|
title.value = post.title;
|
|
|
|
description.value = post.description;
|
|
|
|
isSensitive.value = post.isSensitive;
|
2022-06-20 10:38:49 +02:00
|
|
|
}) : Promise.resolve(null);
|
|
|
|
}, { immediate: true });
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const headerActions = computed(() => []);
|
2022-06-20 10:38:49 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const headerTabs = computed(() => []);
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
definePageMetadata(computed(() => props.postId ? {
|
|
|
|
title: i18n.ts.edit,
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-pencil',
|
2022-06-20 10:38:49 +02:00
|
|
|
} : {
|
|
|
|
title: i18n.ts.postToGallery,
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-pencil',
|
2022-06-20 10:38:49 +02:00
|
|
|
}));
|
2021-04-26 04:10:45 +02:00
|
|
|
</script>
|
|
|
|
|
2022-12-27 10:29:39 +01:00
|
|
|
<style lang="scss" scoped>
|
2021-04-26 04:10:45 +02:00
|
|
|
.wqugxsfx {
|
|
|
|
height: 200px;
|
|
|
|
background-size: contain;
|
|
|
|
background-position: center;
|
|
|
|
background-repeat: no-repeat;
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
left: 9px;
|
|
|
|
padding: 8px;
|
|
|
|
background: var(--panel);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .remove {
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
right: 9px;
|
|
|
|
padding: 8px;
|
|
|
|
background: var(--panel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|