mirror of
https://github.com/Arcadia-Solutions/arcadia.git
synced 2025-12-16 15:04:22 -06:00
feat: edit forum threads, resolves #423
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -591,6 +591,7 @@ dependencies = [
|
||||
"arcadia-shared",
|
||||
"argon2",
|
||||
"bip_metainfo",
|
||||
"cargo-husky",
|
||||
"chrono 0.4.41",
|
||||
"deadpool",
|
||||
"deadpool-redis",
|
||||
@@ -825,6 +826,12 @@ dependencies = [
|
||||
"bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cargo-husky"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b02b629252fe8ef6460461409564e2c21d0c8e77e0944f3d189ff06c4e932ad"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.34"
|
||||
|
||||
@@ -92,6 +92,7 @@ use crate::handlers::user_applications::get_user_applications::GetUserApplicatio
|
||||
crate::handlers::forum::get_forum_thread::exec,
|
||||
crate::handlers::forum::get_forum_thread_posts::exec,
|
||||
crate::handlers::forum::create_forum_thread::exec,
|
||||
crate::handlers::forum::edit_forum_thread::exec,
|
||||
crate::handlers::forum::create_forum_post::exec,
|
||||
crate::handlers::forum::edit_forum_post::exec,
|
||||
crate::handlers::wiki::create_wiki_article::exec,
|
||||
|
||||
44
backend/api/src/handlers/forum/edit_forum_thread.rs
Normal file
44
backend/api/src/handlers/forum/edit_forum_thread.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use crate::{middlewares::auth_middleware::Authdata, Arcadia};
|
||||
use actix_web::{
|
||||
web::{Data, Json},
|
||||
HttpResponse,
|
||||
};
|
||||
use arcadia_common::error::{Error, Result};
|
||||
use arcadia_storage::{
|
||||
models::{
|
||||
forum::{EditedForumThread, ForumThreadEnriched},
|
||||
user::UserClass,
|
||||
},
|
||||
redis::RedisPoolInterface,
|
||||
};
|
||||
|
||||
#[utoipa::path(
|
||||
put,
|
||||
operation_id = "Edit forum thread",
|
||||
tag = "Forum",
|
||||
path = "/api/forum/thread",
|
||||
responses(
|
||||
(status = 200, description = "Edits the thread's information", body=ForumThreadEnriched)
|
||||
)
|
||||
)]
|
||||
pub async fn exec<R: RedisPoolInterface + 'static>(
|
||||
arc: Data<Arcadia<R>>,
|
||||
user: Authdata,
|
||||
edited_forum_thread: Json<EditedForumThread>,
|
||||
) -> Result<HttpResponse> {
|
||||
let original_thread = arc
|
||||
.pool
|
||||
.find_forum_thread(edited_forum_thread.id, user.sub)
|
||||
.await?;
|
||||
|
||||
if user.class != UserClass::Staff && original_thread.created_by_id != user.sub {
|
||||
return Err(Error::InsufficientPrivileges);
|
||||
}
|
||||
|
||||
let updated_thread = arc
|
||||
.pool
|
||||
.update_forum_thread(&edited_forum_thread, user.sub)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(updated_thread))
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod create_forum_post;
|
||||
pub mod create_forum_thread;
|
||||
pub mod edit_forum_post;
|
||||
pub mod edit_forum_thread;
|
||||
pub mod get_forum;
|
||||
pub mod get_forum_sub_category_threads;
|
||||
pub mod get_forum_thread;
|
||||
@@ -14,6 +15,7 @@ pub fn config<R: RedisPoolInterface + 'static>(cfg: &mut ServiceConfig) {
|
||||
cfg.service(
|
||||
resource("/thread")
|
||||
.route(get().to(self::get_forum_thread::exec::<R>))
|
||||
.route(put().to(self::edit_forum_thread::exec::<R>))
|
||||
.route(post().to(self::create_forum_thread::exec::<R>)),
|
||||
);
|
||||
cfg.service(resource("/thread/posts").route(get().to(self::get_forum_thread_posts::exec::<R>)));
|
||||
|
||||
@@ -228,6 +228,9 @@ pub enum Error {
|
||||
#[error("could not update forum post")]
|
||||
CouldNotUpdateForumPost(#[source] sqlx::Error),
|
||||
|
||||
#[error("could not update forum thread")]
|
||||
CouldNotUpdateForumThread(#[source] sqlx::Error),
|
||||
|
||||
#[error("could not find forum post")]
|
||||
CouldNotFindForumPost(#[source] sqlx::Error),
|
||||
|
||||
|
||||
93
backend/storage/.sqlx/query-16054d9e2d7ec808fb594591b889eeaa0cc582f99864c27e9963d6236ec94c63.json
generated
Normal file
93
backend/storage/.sqlx/query-16054d9e2d7ec808fb594591b889eeaa0cc582f99864c27e9963d6236ec94c63.json
generated
Normal file
@@ -0,0 +1,93 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n WITH updated_row AS (\n UPDATE forum_threads\n SET name = $1, sticky = $2, locked = $3, forum_sub_category_id = $4\n WHERE id = $5\n RETURNING *\n )\n SELECT\n ur.id,\n ur.forum_sub_category_id,\n ur.name,\n ur.created_at,\n ur.created_by_id,\n ur.posts_amount,\n ur.sticky,\n ur.locked,\n fsc.name AS forum_sub_category_name,\n fc.name AS forum_category_name,\n fc.id AS forum_category_id,\n (sft.id IS NOT NULL) AS \"is_subscribed!\"\n FROM updated_row ur\n JOIN\n forum_sub_categories AS fsc ON ur.forum_sub_category_id = fsc.id\n JOIN\n forum_categories AS fc ON fsc.forum_category_id = fc.id\n LEFT JOIN\n subscriptions_forum_thread_posts AS sft\n ON sft.forum_thread_id = ur.id AND sft.user_id = $6\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "forum_sub_category_id",
|
||||
"type_info": "Int4"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "name",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "created_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "created_by_id",
|
||||
"type_info": "Int4"
|
||||
},
|
||||
{
|
||||
"ordinal": 5,
|
||||
"name": "posts_amount",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 6,
|
||||
"name": "sticky",
|
||||
"type_info": "Bool"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "locked",
|
||||
"type_info": "Bool"
|
||||
},
|
||||
{
|
||||
"ordinal": 8,
|
||||
"name": "forum_sub_category_name",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 9,
|
||||
"name": "forum_category_name",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 10,
|
||||
"name": "forum_category_id",
|
||||
"type_info": "Int4"
|
||||
},
|
||||
{
|
||||
"ordinal": 11,
|
||||
"name": "is_subscribed!",
|
||||
"type_info": "Bool"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Bool",
|
||||
"Bool",
|
||||
"Int4",
|
||||
"Int8",
|
||||
"Int4"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "16054d9e2d7ec808fb594591b889eeaa0cc582f99864c27e9963d6236ec94c63"
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT\n fp.id,\n fp.content,\n fp.created_at,\n fp.updated_at,\n fp.sticky,\n fp.forum_thread_id,\n u.id AS created_by_user_id,\n u.username AS created_by_user_username,\n u.avatar AS created_by_user_avatar,\n u.banned AS created_by_user_banned,\n u.warned AS created_by_user_warned\n FROM forum_posts fp\n JOIN users u ON fp.created_by_id = u.id\n WHERE fp.forum_thread_id = $1\n ORDER BY fp.created_at ASC\n OFFSET $2\n LIMIT $3\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "content",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "created_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "updated_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "sticky",
|
||||
"type_info": "Bool"
|
||||
},
|
||||
{
|
||||
"ordinal": 5,
|
||||
"name": "forum_thread_id",
|
||||
"type_info": "Int8"
|
||||
},
|
||||
{
|
||||
"ordinal": 6,
|
||||
"name": "created_by_user_id",
|
||||
"type_info": "Int4"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "created_by_user_username",
|
||||
"type_info": "Varchar"
|
||||
},
|
||||
{
|
||||
"ordinal": 8,
|
||||
"name": "created_by_user_avatar",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 9,
|
||||
"name": "created_by_user_banned",
|
||||
"type_info": "Bool"
|
||||
},
|
||||
{
|
||||
"ordinal": 10,
|
||||
"name": "created_by_user_warned",
|
||||
"type_info": "Bool"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Int8",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "75ee76d1d9f14fcfff97dde35a9778bbd425016b3fb6ff878c21cc65d14ac6cb"
|
||||
}
|
||||
@@ -47,6 +47,15 @@ pub struct UserCreatedForumThread {
|
||||
pub first_post: UserCreatedForumPost,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, FromRow, ToSchema)]
|
||||
pub struct EditedForumThread {
|
||||
pub id: i64,
|
||||
pub forum_sub_category_id: i32,
|
||||
pub name: String,
|
||||
pub sticky: bool,
|
||||
pub locked: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, FromRow, ToSchema)]
|
||||
pub struct ForumPost {
|
||||
pub id: i64,
|
||||
|
||||
@@ -3,9 +3,10 @@ use crate::{
|
||||
models::{
|
||||
common::PaginatedResults,
|
||||
forum::{
|
||||
EditedForumPost, ForumPost, ForumPostAndThreadName, ForumPostHierarchy,
|
||||
ForumSearchQuery, ForumSearchResult, ForumThread, ForumThreadEnriched,
|
||||
GetForumThreadPostsQuery, UserCreatedForumPost, UserCreatedForumThread,
|
||||
EditedForumPost, EditedForumThread, ForumPost, ForumPostAndThreadName,
|
||||
ForumPostHierarchy, ForumSearchQuery, ForumSearchResult, ForumThread,
|
||||
ForumThreadEnriched, GetForumThreadPostsQuery, UserCreatedForumPost,
|
||||
UserCreatedForumThread,
|
||||
},
|
||||
user::UserLiteAvatar,
|
||||
},
|
||||
@@ -161,6 +162,56 @@ impl ConnectionPool {
|
||||
Ok(created_forum_thread)
|
||||
}
|
||||
|
||||
pub async fn update_forum_thread(
|
||||
&self,
|
||||
edited_thread: &EditedForumThread,
|
||||
user_id: i32,
|
||||
) -> Result<ForumThreadEnriched> {
|
||||
let updated_thread = sqlx::query_as!(
|
||||
ForumThreadEnriched,
|
||||
r#"
|
||||
WITH updated_row AS (
|
||||
UPDATE forum_threads
|
||||
SET name = $1, sticky = $2, locked = $3, forum_sub_category_id = $4
|
||||
WHERE id = $5
|
||||
RETURNING *
|
||||
)
|
||||
SELECT
|
||||
ur.id,
|
||||
ur.forum_sub_category_id,
|
||||
ur.name,
|
||||
ur.created_at,
|
||||
ur.created_by_id,
|
||||
ur.posts_amount,
|
||||
ur.sticky,
|
||||
ur.locked,
|
||||
fsc.name AS forum_sub_category_name,
|
||||
fc.name AS forum_category_name,
|
||||
fc.id AS forum_category_id,
|
||||
(sft.id IS NOT NULL) AS "is_subscribed!"
|
||||
FROM updated_row ur
|
||||
JOIN
|
||||
forum_sub_categories AS fsc ON ur.forum_sub_category_id = fsc.id
|
||||
JOIN
|
||||
forum_categories AS fc ON fsc.forum_category_id = fc.id
|
||||
LEFT JOIN
|
||||
subscriptions_forum_thread_posts AS sft
|
||||
ON sft.forum_thread_id = ur.id AND sft.user_id = $6
|
||||
"#,
|
||||
edited_thread.name,
|
||||
edited_thread.sticky,
|
||||
edited_thread.locked,
|
||||
edited_thread.forum_sub_category_id,
|
||||
edited_thread.id,
|
||||
user_id
|
||||
)
|
||||
.fetch_one(self.borrow())
|
||||
.await
|
||||
.map_err(Error::CouldNotUpdateForumThread)?;
|
||||
|
||||
Ok(updated_thread)
|
||||
}
|
||||
|
||||
pub async fn find_forum_cateogries_hierarchy(&self) -> Result<Value> {
|
||||
let forum_overview = sqlx::query!(
|
||||
r#"
|
||||
|
||||
1
frontend/.gitignore
vendored
1
frontend/.gitignore
vendored
@@ -39,6 +39,7 @@ vite.config.js
|
||||
vitest.config.js
|
||||
|
||||
.env
|
||||
CLAUDE.md
|
||||
|
||||
# custom frontpage
|
||||
public/home/*
|
||||
|
||||
91
frontend/src/components/forum/EditForumThreadDialog.vue
Normal file
91
frontend/src/components/forum/EditForumThreadDialog.vue
Normal file
@@ -0,0 +1,91 @@
|
||||
<template>
|
||||
<div class="edit-thread-form">
|
||||
<FloatLabel>
|
||||
<InputText v-model="editedThread.name" id="thread-name" class="thread-name-input" />
|
||||
<label for="thread-name">{{ t('forum.thread_name') }}</label>
|
||||
</FloatLabel>
|
||||
|
||||
<FloatLabel>
|
||||
<InputNumber v-model="editedThread.forum_sub_category_id" id="subcategory" />
|
||||
<label for="subcategory">{{ t('forum.subcategory') }}</label>
|
||||
</FloatLabel>
|
||||
|
||||
<div v-if="userStore.class === 'staff'" class="staff-options">
|
||||
<div class="checkbox-row">
|
||||
<Checkbox v-model="editedThread.locked" binary inputId="locked" />
|
||||
<label for="locked">{{ t('general.locked') }}</label>
|
||||
</div>
|
||||
<div class="checkbox-row">
|
||||
<Checkbox v-model="editedThread.sticky" binary inputId="sticky" />
|
||||
<label for="sticky">{{ t('general.sticky') }}</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button :label="t('general.submit')" :loading="submitting" @click="submitEdit" class="submit-button" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { Button, Checkbox, FloatLabel, InputNumber, InputText } from 'primevue'
|
||||
import { editForumThread, type EditedForumThread, type ForumThreadEnriched } from '@/services/api-schema'
|
||||
|
||||
const props = defineProps<{
|
||||
forumThread: ForumThreadEnriched
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
done: [ForumThreadEnriched]
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
const userStore = useUserStore()
|
||||
|
||||
const editedThread = ref<EditedForumThread>({
|
||||
id: props.forumThread.id,
|
||||
name: props.forumThread.name,
|
||||
forum_sub_category_id: props.forumThread.forum_sub_category_id,
|
||||
locked: props.forumThread.locked,
|
||||
sticky: props.forumThread.sticky,
|
||||
})
|
||||
|
||||
const submitting = ref(false)
|
||||
|
||||
const submitEdit = async () => {
|
||||
submitting.value = true
|
||||
editForumThread(editedThread.value)
|
||||
.then((thread) => emit('done', thread))
|
||||
.finally(() => (submitting.value = false))
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.edit-thread-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
min-width: 300px;
|
||||
}
|
||||
|
||||
.thread-name-input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.staff-options {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.checkbox-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.submit-button {
|
||||
align-self: flex-end;
|
||||
}
|
||||
</style>
|
||||
@@ -65,7 +65,9 @@
|
||||
"new": "New",
|
||||
"uses": "Uses",
|
||||
"action": "Action | Actions",
|
||||
"default": "Default"
|
||||
"default": "Default",
|
||||
"locked": "Locked",
|
||||
"sticky": "Sticky"
|
||||
},
|
||||
"auth": {
|
||||
"remember_me": "Remember me"
|
||||
@@ -121,7 +123,9 @@
|
||||
"category": "Category",
|
||||
"subcategory": "Subcategory",
|
||||
"search": "Search forum",
|
||||
"post_edited_success": "Post edited successfully"
|
||||
"post_edited_success": "Post edited successfully",
|
||||
"edit_thread": "Edit thread",
|
||||
"thread_edited_success": "Thread edited successfully"
|
||||
},
|
||||
"user": {
|
||||
"username": "Username",
|
||||
|
||||
@@ -342,6 +342,13 @@ export interface EditedForumPost {
|
||||
'locked': boolean;
|
||||
'sticky': boolean;
|
||||
}
|
||||
export interface EditedForumThread {
|
||||
'forum_sub_category_id': number;
|
||||
'id': number;
|
||||
'locked': boolean;
|
||||
'name': string;
|
||||
'sticky': boolean;
|
||||
}
|
||||
export interface EditedSeries {
|
||||
'banners': Array<string>;
|
||||
'covers': Array<string>;
|
||||
@@ -4097,6 +4104,41 @@ export const ForumApiAxiosParamCreator = function (configuration?: Configuration
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @param {EditedForumThread} editedForumThread
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
editForumThread: async (editedForumThread: EditedForumThread, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
// verify required parameter 'editedForumThread' is not null or undefined
|
||||
assertParamExists('editForumThread', 'editedForumThread', editedForumThread)
|
||||
const localVarPath = `/api/forum/thread`;
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
|
||||
|
||||
localVarHeaderParameter['Content-Type'] = 'application/json';
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
localVarRequestOptions.data = serializeDataIfNeeded(editedForumThread, localVarRequestOptions, configuration)
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @param {*} [options] Override http request option.
|
||||
@@ -4296,6 +4338,18 @@ export const ForumApiFp = function(configuration?: Configuration) {
|
||||
const localVarOperationServerBasePath = operationServerMap['ForumApi.editForumPost']?.[localVarOperationServerIndex]?.url;
|
||||
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @param {EditedForumThread} editedForumThread
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async editForumThread(editedForumThread: EditedForumThread, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ForumThreadEnriched>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.editForumThread(editedForumThread, options);
|
||||
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
||||
const localVarOperationServerBasePath = operationServerMap['ForumApi.editForumThread']?.[localVarOperationServerIndex]?.url;
|
||||
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @param {*} [options] Override http request option.
|
||||
@@ -4382,6 +4436,15 @@ export const ForumApiFactory = function (configuration?: Configuration, basePath
|
||||
editForumPost(editedForumPost: EditedForumPost, options?: RawAxiosRequestConfig): AxiosPromise<ForumPost> {
|
||||
return localVarFp.editForumPost(editedForumPost, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @param {EditedForumThread} editedForumThread
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
editForumThread(editedForumThread: EditedForumThread, options?: RawAxiosRequestConfig): AxiosPromise<ForumThreadEnriched> {
|
||||
return localVarFp.editForumThread(editedForumThread, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @param {*} [options] Override http request option.
|
||||
@@ -4457,6 +4520,16 @@ export class ForumApi extends BaseAPI {
|
||||
return ForumApiFp(this.configuration).editForumPost(editedForumPost, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {EditedForumThread} editedForumThread
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
public editForumThread(editedForumThread: EditedForumThread, options?: RawAxiosRequestConfig) {
|
||||
return ForumApiFp(this.configuration).editForumThread(editedForumThread, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} [options] Override http request option.
|
||||
@@ -4523,6 +4596,12 @@ export const editForumPost = async (editedForumPost: EditedForumPost, options?:
|
||||
};
|
||||
|
||||
|
||||
export const editForumThread = async (editedForumThread: EditedForumThread, options?: RawAxiosRequestConfig): Promise<ForumThreadEnriched> => {
|
||||
const response = await forumApi.editForumThread(editedForumThread, options);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
|
||||
export const getForum = async (options?: RawAxiosRequestConfig): Promise<ForumOverview> => {
|
||||
const response = await forumApi.getForum(options);
|
||||
return response.data;
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
{{ forumThread.name }}
|
||||
</div>
|
||||
<div class="actions">
|
||||
<i
|
||||
v-if="userStore.class === 'staff' || forumThread.created_by_id === userStore.id"
|
||||
class="pi pi-pen-to-square"
|
||||
v-tooltip.top="t('forum.edit_thread')"
|
||||
@click="editThreadDialogVisible = true"
|
||||
/>
|
||||
<i v-if="togglingSubscription" class="pi pi-hourglass" />
|
||||
<i
|
||||
v-else
|
||||
@@ -58,6 +64,9 @@
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
<Dialog closeOnEscape modal :header="t('forum.edit_thread')" v-model:visible="editThreadDialogVisible">
|
||||
<EditForumThreadDialog v-if="forumThread" :forumThread="forumThread" @done="threadEdited" />
|
||||
</Dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -69,9 +78,10 @@ import type { FormSubmitEvent } from '@primevue/forms'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { Form } from '@primevue/forms'
|
||||
import { Button, Message } from 'primevue'
|
||||
import { Button, Message, Dialog } from 'primevue'
|
||||
import BBCodeEditor from '@/components/community/BBCodeEditor.vue'
|
||||
import PaginatedResults from '@/components/PaginatedResults.vue'
|
||||
import EditForumThreadDialog from '@/components/forum/EditForumThreadDialog.vue'
|
||||
import { nextTick } from 'vue'
|
||||
import { scrollToHash } from '@/services/helpers'
|
||||
import { computed } from 'vue'
|
||||
@@ -93,8 +103,10 @@ import {
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const userStore = useUserStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
const editThreadDialogVisible = ref(false)
|
||||
const togglingSubscription = ref(false)
|
||||
const forumThread = ref<null | ForumThreadEnriched>(null)
|
||||
const forumThreadPosts = ref<ForumPostHierarchy[]>([])
|
||||
@@ -187,7 +199,7 @@ const sendPost = async () => {
|
||||
newPost.value.forum_thread_id = parseInt(route.params.id as string)
|
||||
const createdPost: ForumPostHierarchy = {
|
||||
...(await createForumPost(newPost.value)),
|
||||
created_by: useUserStore(),
|
||||
created_by: userStore,
|
||||
}
|
||||
newPost.value.content = ''
|
||||
forumThreadPosts.value.push(createdPost)
|
||||
@@ -214,6 +226,14 @@ const changePage = (page: number) => {
|
||||
router.push({ query: { page } })
|
||||
}
|
||||
|
||||
const threadEdited = (editedThread: ForumThreadEnriched) => {
|
||||
if (forumThread.value) {
|
||||
forumThread.value = editedThread
|
||||
editThreadDialogVisible.value = false
|
||||
showToast('', t('forum.thread_edited_success'), 'success', 2000)
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.query,
|
||||
() => {
|
||||
@@ -230,6 +250,9 @@ watch(
|
||||
align-items: flex-end;
|
||||
.actions {
|
||||
cursor: pointer;
|
||||
i {
|
||||
margin-left: 7px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.new-post {
|
||||
|
||||
Reference in New Issue
Block a user