Fix PR 3 review findings [skip ci]
This commit is contained in:
1 parent
590178e41a
commit
454620f21e
21 files changed
+522
-160
No files matched your search
@@ -607,6 +607,8 @@ pub async fn create_guild(
|
||||
name: String,
|
||||
tag: String,
|
||||
description: String,
|
||||
icon_url: Option<String>,
|
||||
banner_url: Option<String>,
|
||||
) -> Res<Guild> {
|
||||
let req = account_api(&state, reqwest::Method::POST, "/guilds").await?;
|
||||
let resp = req.json(&serde_json::json!({
|
||||
@@ -614,6 +616,8 @@ pub async fn create_guild(
|
||||
"name": name,
|
||||
"tag": tag,
|
||||
"description": description,
|
||||
"icon_url": icon_url,
|
||||
"banner_url": banner_url,
|
||||
})).send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
@@ -950,12 +954,12 @@ pub async fn create_user_post(
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn like_user_post(state: State<'_, AppState>, post_id: i64) -> Res<()> {
|
||||
pub async fn like_user_post(state: State<'_, AppState>, post_id: i64) -> Res<bool> {
|
||||
let req = account_api(&state, reqwest::Method::POST, &format!("/posts/{post_id}/like")).await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
if !resp.status().is_success() {
|
||||
return Err("unable to like post".into());
|
||||
}
|
||||
Ok(())
|
||||
let body: serde_json::Value = resp.json().await.map_err(err)?;
|
||||
Ok(body["liked"].as_bool().unwrap_or(false))
|
||||
}
|
||||
|
||||
@@ -88,9 +88,11 @@
|
||||
}
|
||||
|
||||
async function handleLikePost(post: UserPost) {
|
||||
if (post.liked_by_me) return;
|
||||
try {
|
||||
await invoke('like_user_post', { postId: post.id });
|
||||
post.likes_count += 1;
|
||||
const liked = await invoke<boolean>('like_user_post', { postId: post.id });
|
||||
if (liked) post.likes_count += 1;
|
||||
post.liked_by_me = true;
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to update like', 'error');
|
||||
}
|
||||
|
||||
@@ -106,9 +106,9 @@
|
||||
return `${hours}h ${mins}m`;
|
||||
} else {
|
||||
const day = now.getUTCDay();
|
||||
const daysUntilSunday = (7 - day) % 7 || 7;
|
||||
const nextSunday = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + daysUntilSunday));
|
||||
const diffMs = nextSunday.getTime() - now.getTime();
|
||||
const daysUntilMonday = (8 - day) % 7 || 7;
|
||||
const nextMonday = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + daysUntilMonday));
|
||||
const diffMs = nextMonday.getTime() - now.getTime();
|
||||
const days = Math.floor(diffMs / (1000 * 60 * 60 * 24));
|
||||
const hours = Math.floor((diffMs % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
||||
return `${days}d ${hours}h`;
|
||||
|
||||
Reference in new issue
Block a user