add: stacks mode and sort
This commit is contained in:
parent
281e9bea44
commit
d174b44f57
9 changed files with 272 additions and 18 deletions
|
@ -16,13 +16,13 @@
|
|||
|
||||
<div class="w-full flex flex-col gap-2" data-tab="general">
|
||||
<div id="manage_fields" class="card tertiary flex flex-col gap-2">
|
||||
<div class="card-nest" ui_ident="privacu">
|
||||
<div class="card-nest" ui_ident="privacy">
|
||||
<div class="card small">
|
||||
<b>Privacy</b>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<select onchange="save_privacy(event, 'read')">
|
||||
<select onchange="save_privacy(event)">
|
||||
<option
|
||||
value="Private"
|
||||
selected="{% if stack.privacy == 'Private' %}true{% else %}false{% endif %}"
|
||||
|
@ -39,6 +39,52 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-nest" ui_ident="mode">
|
||||
<div class="card small">
|
||||
<b>Mode</b>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<select onchange="save_mode(event)">
|
||||
<option
|
||||
value="Include"
|
||||
selected="{% if stack.mode == 'Include' %}true{% else %}false{% endif %}"
|
||||
>
|
||||
Include
|
||||
</option>
|
||||
<option
|
||||
value="Exclude"
|
||||
selected="{% if stack.mode == 'Exclude' %}true{% else %}false{% endif %}"
|
||||
>
|
||||
Exclude
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-nest" ui_ident="sort">
|
||||
<div class="card small">
|
||||
<b>Sort</b>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<select onchange="save_sort(event)">
|
||||
<option
|
||||
value="Created"
|
||||
selected="{% if stack.sort == 'Created' %}true{% else %}false{% endif %}"
|
||||
>
|
||||
Created
|
||||
</option>
|
||||
<option
|
||||
value="Likes"
|
||||
selected="{% if stack.sort == 'Likes' %}true{% else %}false{% endif %}"
|
||||
>
|
||||
Likes
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-nest" ui_ident="change_name">
|
||||
<div class="card small">
|
||||
<b>{{ text "stacks:label.change_name" }}</b>
|
||||
|
@ -186,6 +232,46 @@
|
|||
});
|
||||
};
|
||||
|
||||
globalThis.save_mode = (event, mode) => {
|
||||
const selected = event.target.selectedOptions[0];
|
||||
fetch(`/api/v1/stacks/{{ stack.id }}/mode`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
mode: selected.value,
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
};
|
||||
|
||||
globalThis.save_sort = (event, mode) => {
|
||||
const selected = event.target.selectedOptions[0];
|
||||
fetch(`/api/v1/stacks/{{ stack.id }}/sort`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
sort: selected.value,
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
};
|
||||
|
||||
globalThis.change_name = async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ use tetratto_core::model::{
|
|||
communities_permissions::CommunityPermission,
|
||||
permissions::FinePermission,
|
||||
reactions::AssetType,
|
||||
stacks::StackPrivacy,
|
||||
stacks::{StackMode, StackPrivacy, StackSort},
|
||||
};
|
||||
|
||||
pub fn routes() -> Router {
|
||||
|
@ -326,6 +326,8 @@ pub fn routes() -> Router {
|
|||
.route("/stacks", post(stacks::create_request))
|
||||
.route("/stacks/{id}/name", post(stacks::update_name_request))
|
||||
.route("/stacks/{id}/privacy", post(stacks::update_privacy_request))
|
||||
.route("/stacks/{id}/mode", post(stacks::update_mode_request))
|
||||
.route("/stacks/{id}/sort", post(stacks::update_sort_request))
|
||||
.route("/stacks/{id}/users", post(stacks::add_user_request))
|
||||
.route("/stacks/{id}/users", delete(stacks::remove_user_request))
|
||||
.route("/stacks/{id}", delete(stacks::delete_request))
|
||||
|
@ -531,6 +533,16 @@ pub struct UpdateStackPrivacy {
|
|||
pub privacy: StackPrivacy,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateStackMode {
|
||||
pub mode: StackMode,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateStackSort {
|
||||
pub sort: StackSort,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct AddOrRemoveStackUser {
|
||||
pub username: String,
|
||||
|
|
|
@ -2,7 +2,10 @@ use crate::{State, get_user_from_token};
|
|||
use axum::{Extension, Json, extract::Path, response::IntoResponse};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{stacks::UserStack, ApiReturn, Error};
|
||||
use super::{AddOrRemoveStackUser, CreateStack, UpdateStackName, UpdateStackPrivacy};
|
||||
use super::{
|
||||
AddOrRemoveStackUser, CreateStack, UpdateStackMode, UpdateStackName, UpdateStackPrivacy,
|
||||
UpdateStackSort,
|
||||
};
|
||||
|
||||
pub async fn create_request(
|
||||
jar: CookieJar,
|
||||
|
@ -72,6 +75,50 @@ pub async fn update_privacy_request(
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn update_mode_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
Json(req): Json<UpdateStackMode>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data.update_stack_mode(id, user, req.mode).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Stack updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn update_sort_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
Json(req): Json<UpdateStackSort>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data.update_stack_sort(id, user, req.sort).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Stack updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn add_user_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
|
|
|
@ -66,15 +66,12 @@ pub async fn posts_request(
|
|||
}
|
||||
|
||||
let ignore_users = data.0.get_userblocks_receivers(user.id).await;
|
||||
let list = match data.0.get_posts_from_stack(stack.id, 12, req.page).await {
|
||||
Ok(l) => match data
|
||||
.0
|
||||
.fill_posts_with_community(l, user.id, &ignore_users)
|
||||
.await
|
||||
{
|
||||
Ok(l) => l,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
},
|
||||
let list = match data
|
||||
.0
|
||||
.get_stack_posts(user.id, stack.id, 12, req.page, &ignore_users)
|
||||
.await
|
||||
{
|
||||
Ok(l) => l,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue