add: 8 more achievements

This commit is contained in:
trisua 2025-06-27 14:21:42 -04:00
parent 8d70f65863
commit a799c777ea
11 changed files with 121 additions and 18 deletions

View file

@ -1084,10 +1084,12 @@
("href" "/journals/0/0")
(icon (text "notebook"))
(str (text "general:link.journals")))
(text "{% if not user.settings.disable_achievements -%}")
(a
("href" "/achievements")
(icon (text "award"))
(str (text "general:link.achievements")))
(text "{%- endif %}")
(a
("href" "/settings")
(text "{{ icon \"settings\" }}")

View file

@ -1553,6 +1553,11 @@
\"{{ profile.settings.disable_gpa_fun }}\",
\"checkbox\",
],
[
[\"disable_achievements\", \"Disable achievements\"],
\"{{ profile.settings.disable_achievements }}\",
\"checkbox\",
],
],
settings,
);

View file

@ -979,7 +979,13 @@
self.define(
"timestamp",
({ $ }, updated_, progress_ms_, duration_ms_, display = "full") => {
async (
{ $ },
updated_,
progress_ms_,
duration_ms_,
display = "full",
) => {
if (duration_ms_ === "0") {
return;
}
@ -1003,7 +1009,7 @@
}
if (display === "full") {
return `${$.ms_time_text(progress_ms)}/${$.ms_time_text(duration_ms)} <span class="fade">(${Math.floor((progress_ms / duration_ms) * 100)}%)</span>`;
return `${await $.ms_time_text(progress_ms)}/${await $.ms_time_text(duration_ms)} <span class="fade">(${Math.floor((progress_ms / duration_ms) * 100)}%)</span>`;
}
if (display === "left") {

View file

@ -292,11 +292,10 @@ pub async fn create_membership(
};
match data
.create_membership(CommunityMembership::new(
user.id,
id,
CommunityPermission::default(),
))
.create_membership(
CommunityMembership::new(user.id, id, CommunityPermission::default()),
&user,
)
.await
{
Ok(m) => Json(ApiReturn {

View file

@ -4,7 +4,7 @@ use axum::{
Extension, Json,
};
use axum_extra::extract::CookieJar;
use tetratto_core::model::{communities::PostDraft, oauth, ApiReturn, Error};
use tetratto_core::model::{auth::AchievementName, communities::PostDraft, oauth, ApiReturn, Error};
use crate::{
get_user_from_token,
routes::{
@ -20,11 +20,20 @@ pub async fn create_request(
Json(req): Json<CreatePostDraft>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
let user = match get_user_from_token!(jar, data, oauth::AppScope::UserCreateDrafts) {
let mut user = match get_user_from_token!(jar, data, oauth::AppScope::UserCreateDrafts) {
Some(ua) => ua,
None => return Json(Error::NotAllowed.into()),
};
// award achievement
if let Err(e) = data
.add_achievement(&mut user, AchievementName::CreateDraft.into())
.await
{
return Json(e.into());
}
// ...
match data
.create_draft(PostDraft::new(req.content, user.id))
.await

View file

@ -341,11 +341,20 @@ pub async fn update_content_request(
Json(req): Json<UpdatePostContent>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
let user = match get_user_from_token!(jar, data, oauth::AppScope::UserEditPosts) {
let mut user = match get_user_from_token!(jar, data, oauth::AppScope::UserEditPosts) {
Some(ua) => ua,
None => return Json(Error::NotAllowed.into()),
};
// award achievement
if let Err(e) = data
.add_achievement(&mut user, AchievementName::EditPost.into())
.await
{
return Json(e.into());
}
// ...
match data.update_post_content(id, user, req.content).await {
Ok(_) => Json(ApiReturn {
ok: true,