Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions components/pages/posts/post/PostComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
const { isPremium } = useUserData()

const areTagsOpen = ref(false)
const isCollapsed = ref(false)

function toggleCollapsedState() {
isCollapsed.value = !isCollapsed.value

if (!isCollapsed.value) {
return
}

areTagsOpen.value = false
}

const mediaFile = computed(() => {
const stripFragment = (url?: string | null) => url?.split('#')[0] ?? null
Expand Down Expand Up @@ -96,19 +107,42 @@
const tagTypesWithTags = computed(() => {
return Object.keys(props.post.tags).filter((tagType) => props.post.tags[tagType].length > 0)
})

const collapsedSummary = computed(() => {
const mediaLabel = props.post.media_type === 'animated' ? 'animation' : props.post.media_type

return `${mediaLabel} #${props.post.id} hidden`
})
</script>

<template>
<figure class="border-base-0/20 rounded-md border">
<PostMedia
:mediaAlt="mediaFile.alt"
:mediaPosterSrc="mediaFile.posterFile"
:mediaSrc="mediaFile.file"
:mediaSrcHeight="mediaFile.height"
:mediaSrcWidth="mediaFile.width"
:mediaType="post.media_type"
:postIndex="props.postIndex"
/>
<div
v-if="!isCollapsed"
:title="`Double-click to hide post #${post.id}`"
@dblclick="toggleCollapsedState"
>
<PostMedia
:mediaAlt="mediaFile.alt"
:mediaPosterSrc="mediaFile.posterFile"
:mediaSrc="mediaFile.file"
:mediaSrcHeight="mediaFile.height"
:mediaSrcWidth="mediaFile.width"
:mediaType="post.media_type"
:postIndex="props.postIndex"
/>
</div>

<button
v-else
:aria-label="`Show post #${post.id}`"
class="hover:hover-bg-util focus-visible:focus-outline-util text-base-content flex min-h-28 w-full flex-col items-center justify-center gap-2 rounded-t-md px-4 py-4 text-center"
type="button"
@click="toggleCollapsedState"
>
<span class="text-base-content-highlight text-sm font-semibold">{{ collapsedSummary }}</span>
<span class="text-base-content/80 text-xs">Click to show it again</span>
</button>

<figcaption>
<!-- Post description -->
Expand Down