2022-11-23 20:17:54 +03:00
|
|
|
<script setup lang="ts">
|
2023-01-08 09:21:09 +03:00
|
|
|
import type { mastodon } from 'masto'
|
2022-11-23 20:17:54 +03:00
|
|
|
|
2022-12-15 02:30:54 +03:00
|
|
|
const props = withDefaults(defineProps<{
|
2023-01-08 09:21:09 +03:00
|
|
|
attachment: mastodon.v1.MediaAttachment
|
2022-11-23 20:17:54 +03:00
|
|
|
alt?: string
|
|
|
|
removable?: boolean
|
2022-12-16 22:55:31 +03:00
|
|
|
dialogLabelledBy?: string
|
2022-11-23 20:17:54 +03:00
|
|
|
}>(), {
|
|
|
|
removable: true,
|
|
|
|
})
|
|
|
|
|
2022-12-23 17:08:10 +03:00
|
|
|
const emit = defineEmits<{
|
2022-11-23 20:17:54 +03:00
|
|
|
(evt: 'remove'): void
|
2022-12-15 02:30:54 +03:00
|
|
|
(evt: 'setDescription', description: string): void
|
2022-11-23 20:17:54 +03:00
|
|
|
}>()
|
2022-12-15 02:30:54 +03:00
|
|
|
|
2023-03-06 16:12:31 +03:00
|
|
|
// from https://github.com/mastodon/mastodon/blob/dfa984/app/models/media_attachment.rb#L40
|
|
|
|
const maxDescriptionLength = 1500
|
|
|
|
|
2022-12-15 02:30:54 +03:00
|
|
|
const isEditDialogOpen = ref(false)
|
2022-12-15 02:40:39 +03:00
|
|
|
const description = ref(props.attachment.description ?? '')
|
2023-03-30 22:01:24 +03:00
|
|
|
function toggleApply() {
|
2022-12-23 17:08:10 +03:00
|
|
|
isEditDialogOpen.value = false
|
|
|
|
emit('setDescription', unref(description))
|
|
|
|
}
|
2022-11-23 20:17:54 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div relative group>
|
2023-02-15 13:34:23 +03:00
|
|
|
<StatusAttachment :attachment="attachment" w-full is-preview />
|
2022-11-24 07:05:13 +03:00
|
|
|
<div absolute right-2 top-2>
|
|
|
|
<div
|
|
|
|
v-if="removable"
|
2022-12-22 13:59:25 +03:00
|
|
|
:aria-label="$t('attachment.remove_label')"
|
2023-01-21 13:52:36 +03:00
|
|
|
class="bg-black/75 hover:bg-red/75"
|
|
|
|
text-white px2 py2 rounded-full cursor-pointer
|
2022-11-24 07:05:13 +03:00
|
|
|
@click="$emit('remove')"
|
|
|
|
>
|
2023-01-30 13:58:18 +03:00
|
|
|
<div i-ri:close-line text-3 text-6 md:text-3 />
|
2022-11-24 07:05:13 +03:00
|
|
|
</div>
|
2022-11-23 20:17:54 +03:00
|
|
|
</div>
|
2022-12-15 02:30:54 +03:00
|
|
|
<div absolute right-2 bottom-2>
|
|
|
|
<button class="bg-black/75" text-white px2 py1 rounded-2 @click="isEditDialogOpen = true">
|
2022-12-22 13:59:25 +03:00
|
|
|
{{ $t('action.edit') }}
|
2022-12-15 02:30:54 +03:00
|
|
|
</button>
|
|
|
|
</div>
|
2022-12-16 22:55:31 +03:00
|
|
|
<ModalDialog
|
|
|
|
v-model="isEditDialogOpen"
|
|
|
|
:dialog-labelled-by="dialogLabelledBy"
|
|
|
|
py-6
|
|
|
|
px-6 max-w-300
|
|
|
|
>
|
2022-12-23 12:09:52 +03:00
|
|
|
<div flex flex-col-reverse gap-5 md:flex-row>
|
2022-12-15 02:30:54 +03:00
|
|
|
<div flex flex-col gap-2 justify-between>
|
2022-12-16 22:55:31 +03:00
|
|
|
<h1 id="edit-attachment" font-bold>
|
2022-12-22 13:59:25 +03:00
|
|
|
{{ $t('attachment.edit_title') }}
|
2022-12-15 02:30:54 +03:00
|
|
|
</h1>
|
|
|
|
<div flex flex-col gap-2>
|
2022-12-23 12:09:52 +03:00
|
|
|
<textarea v-model="description" p-3 h-50 bg-base rounded-2 border-strong border-1 md:w-100 />
|
2023-03-06 16:12:31 +03:00
|
|
|
<div flex flex-row-reverse>
|
|
|
|
<PublishCharacterCounter :length="description.length" :max="maxDescriptionLength" />
|
|
|
|
</div>
|
|
|
|
<button btn-outline :disabled="description.length > maxDescriptionLength" @click="toggleApply">
|
2022-12-22 13:59:25 +03:00
|
|
|
{{ $t('action.apply') }}
|
2022-12-15 02:30:54 +03:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<button btn-outline @click="isEditDialogOpen = false">
|
2022-12-22 13:59:25 +03:00
|
|
|
{{ $t('action.close') }}
|
2022-12-15 02:30:54 +03:00
|
|
|
</button>
|
|
|
|
</div>
|
2023-02-15 13:34:23 +03:00
|
|
|
<StatusAttachment :attachment="attachment" w-full is-preview />
|
2022-12-15 02:30:54 +03:00
|
|
|
</div>
|
|
|
|
</ModalDialog>
|
2022-11-23 20:17:54 +03:00
|
|
|
</div>
|
|
|
|
</template>
|