This commit is contained in:
parent
a3b3b73dab
commit
369453794b
3 changed files with 65 additions and 4 deletions
40
frontend-vue/src/components/note/Note.vue
Normal file
40
frontend-vue/src/components/note/Note.vue
Normal file
|
@ -0,0 +1,40 @@
|
|||
<script setup lang="ts">
|
||||
import PreviewHeader from '@/components/user/PreviewHeader.vue'
|
||||
import type { Note as NoteData } from '@/stores/note.ts'
|
||||
import { ref } from 'vue'
|
||||
import FormattedText from '@/components/util/FormattedText.vue'
|
||||
|
||||
const props = defineProps<{
|
||||
note: NoteData;
|
||||
}>()
|
||||
|
||||
let collapsed = ref<boolean>(true);
|
||||
|
||||
function shortenContent(): string {
|
||||
if (!collapsed.value) return props.note.rawContent;
|
||||
if (props.note.rawContent.length > 200) {
|
||||
const words = props.note.rawContent.split(' ');
|
||||
let outString = '';
|
||||
for (const word of words) {
|
||||
if (outString.length > 200) {
|
||||
return outString + '...';
|
||||
}
|
||||
outString += word + ' ';
|
||||
}
|
||||
return outString;
|
||||
} else {
|
||||
return props.note.rawContent;
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- Preview for reply here, decide if this component can also serve as such a preview -->
|
||||
<PreviewHeader :user="props.note.owner" />
|
||||
<FormattedText :raw-text="shortenContent" :hashtags="props.note.hashtags" :pinged="props.note.pings" />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
|
@ -1,11 +1,21 @@
|
|||
<script setup lang="ts">
|
||||
import type { User } from '@/stores/userdata.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
rawText: string // Raw text (already pre-transformed by server into Linstrom format)
|
||||
// User pings and hashtags not in here will not be highlighted
|
||||
// Important for username rendering
|
||||
pinged?: User[]
|
||||
hashtags?: string[]
|
||||
}>()
|
||||
// TODO: Start figuring out how to format this stuff.
|
||||
// Probably something akin to the treeificator. Marshal text into tree first,
|
||||
// then adjust tree nodes to types that unmarshal into html
|
||||
// TODO: Start figuring out how to format this stuff.
|
||||
// Probably something akin to the treeificator. Marshal text into tree first,
|
||||
// then adjust tree nodes to types that unmarshal into html
|
||||
// Or single pass transform, keeping a stack of the current context
|
||||
function render(): string {
|
||||
return props.rawText
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<p>{{props.rawText}}</p>
|
||||
<div v-html="render" />
|
||||
</template>
|
||||
|
|
11
frontend-vue/src/stores/note.ts
Normal file
11
frontend-vue/src/stores/note.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import type { User } from '@/stores/userdata.ts'
|
||||
|
||||
export interface Note {
|
||||
id: string;
|
||||
rawContent: string;
|
||||
owner: User;
|
||||
repliesTo?: Note;
|
||||
quotes?: Note[];
|
||||
pings: User[];
|
||||
hashtags: string[];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue