Some fixes and additions

This commit is contained in:
Torsten Schulz
2025-07-09 14:28:35 +02:00
parent 5029be81e9
commit fceea5b7fb
32 changed files with 4373 additions and 1294 deletions

View File

@@ -2,89 +2,84 @@
<h2 class="link" @click="openForum()">{{ $t('socialnetwork.forum.title') }} {{ forumName }}</h2>
<h3 v-if="forumTopic">{{ forumTopic }}</h3>
<ul class="messages">
<li v-for="message in messages">
<li v-for="message in messages" :key="message.id">
<div v-html="message.text"></div>
<div class="footer">
<span class="link" @click="openProfile(message.lastMessageUser.hashedId)">{{
message.lastMessageUser.username }}</span>
<span class="link" @click="openProfile(message.lastMessageUser.hashedId)">
{{ message.lastMessageUser.username }}
</span>
<span>{{ new Date(message.createdAt).toLocaleString() }}</span>
</div>
</li>
</ul>
<editor v-model="newContent" :init="tinymceInitOptions" :api-key="apiKey"
tinymce-script-src="/tinymce/tinymce.min.js"></editor>
<div class="editor-container">
<EditorContent :editor="editor" class="editor" />
</div>
<button @click="saveNewMessage">{{ $t('socialnetwork.forum.createNewMesssage') }}</button>
</template>
<script>
import apiClient from '../../utils/axios';
import TinyMCEEditor from '@tinymce/tinymce-vue';
import { Editor, EditorContent } from '@tiptap/vue-3'
import StarterKit from '@tiptap/starter-kit'
import apiClient from '../../utils/axios'
export default {
name: 'ForumTopicView',
components: {
editor: TinyMCEEditor,
EditorContent,
},
data() {
return {
forumTopicId: String,
forumTopicId: '',
forumTopic: null,
forumName: null,
forumId: 0,
newContent: '',
apiKey: import.meta.env.VITE_TINYMCE_API_KEY ?? '',
tinymceInitOptions: {
script_url: '/tinymce/tinymce.min.js',
height: 300,
menubar: true,
plugins: [
'lists', 'link',
'searchreplace', 'visualblocks', 'code',
'insertdatetime', 'table'
],
toolbar:
'undo redo cut copy paste | bold italic forecolor backcolor fontfamily fontsize| \
alignleft aligncenter alignright alignjustify | \
bullist numlist outdent indent | removeformat | link visualblocks code',
contextmenu: 'link image table',
menubar: 'edit format table',
promotion: false,
},
messages: [],
editor: null,
}
},
async mounted() {
mounted() {
this.forumTopicId = this.$route.params.id;
this.loadForumTopic();
this.editor = new Editor({
extensions: [StarterKit],
content: '',
});
},
beforeUnmount() {
if (this.editor) {
this.editor.destroy();
}
},
methods: {
async loadForumTopic() {
try {
console.log(this.forumTopicId);
const url = `/api/forum/topic/${this.forumTopicId}`;
console.log('url', url);
const response = await apiClient.get(url);
const response = await apiClient.get(`/api/forum/topic/${this.forumTopicId}`);
this.setContent(response.data);
} catch (error) {
console.error(error);
}
},
setContent(responseData) {
this.forumTopic = responseData.title;
this.forumName = responseData.forum.name;
this.forumId = responseData.forum.id;
this.messages = responseData.messages;
setContent(data) {
this.forumTopic = data.title;
this.forumName = data.forum.name;
this.forumId = data.forum.id;
this.messages = data.messages;
},
async openProfile(id) {
this.$root.$refs.userProfileDialog.userId = id;
this.$root.$refs.userProfileDialog.open();
},
async saveNewMessage() {
const content = this.editor ? this.editor.getHTML() : '';
if (!content.trim()) return;
try {
const url = `/api/forum/topic/${this.forumTopicId}/message`;
const response = await apiClient.post(url, {
content: this.newContent,
});
this.newContent = '';
const response = await apiClient.post(url, { content });
this.editor.commands.clearContent();
this.setContent(response.data);
} catch (error) {
console.error(error);
@@ -96,7 +91,6 @@ export default {
}
}
</script>
<style lang="scss" scoped>
.messages {
list-style-type: none;
@@ -117,11 +111,24 @@ export default {
display: flex;
}
.messages>li>.footer>span:first-child {
.messages > li > .footer > span:first-child {
flex: 1;
}
.messages > li > .footer > span:last-child {
text-align: right;
}
</style>
.editor-container {
margin-top: 1rem;
border: 1px solid #ccc;
padding: 10px;
min-height: 200px;
background-color: white;
}
.editor {
min-height: 150px;
outline: none;
}
</style>