Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
<p
class="mb-3 whitespace-pre-wrap wrap-break-word"
style="unicode-bidi: plaintext"
v-html="parseLinks(content.text, false, false, content.mentions)"
v-html="displayText"
/>

<!-- Media (Images and Videos) -->
<button
v-if="shouldShowMore"
@click.stop="toggleExpanded"
class="text-accent hover:underline font-medium text-sm mt-1"
>
{{ isExpanded ? 'Show less' : 'Show more' }}
</button>

<div @click.stop>
<TweetMedia
v-if="
Expand All @@ -22,7 +29,7 @@
<!-- Quoted Tweet -->
<QuotedTweet
v-if="content.parentTweet || content.quotedTweet"
:tweet="content.parentTweet || content.quotedTweet"
:tweet="(content.parentTweet || content.quotedTweet)!"
/>
</div>
</template>
Expand All @@ -32,7 +39,7 @@ import type { Content } from '~/modules/tweets/types'
import TweetMedia from '../TweetMedia/TweetMedia.vue'
import QuotedTweet from '../QuotedTweet/QuotedTweet.vue'

import { ref, onMounted, onBeforeUnmount } from 'vue'
import { ref, computed, onMounted, onBeforeUnmount } from 'vue'
import { useRouter } from 'vue-router'
import { parseLinks } from '~/lib/utils'

Expand All @@ -42,6 +49,28 @@ const props = defineProps<{

const root = ref<HTMLElement | null>(null)
const router = useRouter()
const isExpanded = ref(false)
const MAX_LENGTH = 200

const shouldShowMore = computed(() => {
return props.content.text.length > MAX_LENGTH
})

const displayText = computed(() => {
const text = props.content.text
const parsedText = parseLinks(text, false, false, props.content.mentions)

if (!shouldShowMore.value || isExpanded.value) {
return parsedText
}

const truncatedText = text.substring(0, MAX_LENGTH)
return parseLinks(truncatedText, false, false, props.content.mentions)
})

const toggleExpanded = () => {
isExpanded.value = !isExpanded.value
}

function onRootClick(e: Event) {
const target = e.target as HTMLElement | null
Expand Down