add: notifications for likes
TODO: notifications ui
This commit is contained in:
parent
6413ed09fb
commit
9dc75d7095
9 changed files with 292 additions and 27 deletions
|
@ -600,6 +600,10 @@ nav .button:not(.title):not(.active):hover {
|
|||
top: unset;
|
||||
}
|
||||
|
||||
body {
|
||||
padding-bottom: 72px;
|
||||
}
|
||||
|
||||
nav button:not(.dropdown *),
|
||||
nav .button:not(.dropdown *) {
|
||||
font-size: 12px;
|
||||
|
|
|
@ -25,18 +25,6 @@
|
|||
</h3>
|
||||
|
||||
<span class="fade">{{ community.title }}</span>
|
||||
|
||||
{% if user %}
|
||||
<div
|
||||
class="flex gap-1 reactions_box"
|
||||
hook="check_reactions"
|
||||
hook-arg:id="{{ community.id }}"
|
||||
>
|
||||
{{ components::likes(id=community.id,
|
||||
asset_type="Community", likes=community.likes,
|
||||
dislikes=community.dislikes) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -69,7 +57,51 @@
|
|||
<div
|
||||
id="manage_fields"
|
||||
class="flex flex-col gap-2"
|
||||
></div>
|
||||
>
|
||||
<div class="card-nest">
|
||||
<div class="card small">
|
||||
<b>Read access</b>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<select
|
||||
onchange="save_access(event, 'read')"
|
||||
>
|
||||
<option value="Everybody">
|
||||
Everybody
|
||||
</option>
|
||||
<option value="Unlisted">
|
||||
Unlisted
|
||||
</option>
|
||||
<option value="Private">
|
||||
Private
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-nest">
|
||||
<div class="card small">
|
||||
<b>Write access</b>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<select
|
||||
onchange="save_access(event, 'write')"
|
||||
>
|
||||
<option value="Everybody">
|
||||
Everybody
|
||||
</option>
|
||||
<option value="Joined">
|
||||
Joined
|
||||
</option>
|
||||
<option value="Owner">
|
||||
Owner only
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="margin" />
|
||||
|
||||
|
@ -96,7 +128,7 @@
|
|||
document.getElementById("manage_fields"),
|
||||
[
|
||||
[
|
||||
["display_name", "Title"],
|
||||
["display_name", "Display title"],
|
||||
"{{ community.context.display_name }}",
|
||||
"input",
|
||||
],
|
||||
|
@ -111,7 +143,7 @@
|
|||
|
||||
window.save_context = () => {
|
||||
fetch(
|
||||
`/api/v1/communities/{{ community.id }}/context`,
|
||||
"/api/v1/communities/{{ community.id }}/context",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
@ -131,6 +163,31 @@
|
|||
]);
|
||||
});
|
||||
};
|
||||
|
||||
window.save_access = (event, mode) => {
|
||||
const selected =
|
||||
event.target.selectedOptions[0];
|
||||
fetch(
|
||||
`/api/v1/communities/{{ community.id }}/access/${mode}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type":
|
||||
"application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
access: selected.value,
|
||||
}),
|
||||
},
|
||||
)
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
};
|
||||
}, 250);
|
||||
</script>
|
||||
{% endif %}
|
||||
|
@ -159,6 +216,28 @@
|
|||
<span class="notification chip">Created</span>
|
||||
<span class="date">{{ community.created }}</span>
|
||||
</div>
|
||||
|
||||
<div class="w-full flex justify-between items-center">
|
||||
<span class="notification chip">Score</span>
|
||||
<div class="flex gap-2">
|
||||
<b
|
||||
>{{ community.likes - community.dislikes
|
||||
}}</b
|
||||
>
|
||||
{% if user %}
|
||||
<div
|
||||
class="flex gap-1 reactions_box"
|
||||
hook="check_reactions"
|
||||
hook-arg:id="{{ community.id }}"
|
||||
>
|
||||
{{ components::likes(id=community.id,
|
||||
asset_type="Community",
|
||||
likes=community.likes,
|
||||
dislikes=community.dislikes) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
pub mod auth;
|
||||
pub mod communities;
|
||||
pub mod notifications;
|
||||
pub mod reactions;
|
||||
|
||||
use axum::{
|
||||
|
@ -120,6 +121,16 @@ pub fn routes() -> Router {
|
|||
"/auth/profile/find/{id}",
|
||||
get(auth::profile::redirect_from_id),
|
||||
)
|
||||
// notifications
|
||||
.route(
|
||||
"/notifications/my",
|
||||
delete(notifications::delete_all_request),
|
||||
)
|
||||
.route("/notifications/{id}", delete(notifications::delete_request))
|
||||
.route(
|
||||
"/notifications/{id}/read",
|
||||
delete(notifications::update_read_status_request),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -182,3 +193,8 @@ pub struct CreateReaction {
|
|||
pub struct UpdateUserIsVerified {
|
||||
pub is_verified: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateNotificationRead {
|
||||
pub read: bool,
|
||||
}
|
||||
|
|
70
crates/app/src/routes/api/v1/notifications.rs
Normal file
70
crates/app/src/routes/api/v1/notifications.rs
Normal file
|
@ -0,0 +1,70 @@
|
|||
use axum::{Extension, Json, extract::Path, response::IntoResponse};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{ApiReturn, Error};
|
||||
|
||||
use crate::{State, get_user_from_token};
|
||||
|
||||
use super::UpdateNotificationRead;
|
||||
|
||||
pub async fn delete_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
) -> 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.delete_notification(id, &user).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Notification deleted".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn delete_all_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
) -> 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.delete_all_notifications(&user).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Notifications deleted".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn update_read_status_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
Json(req): Json<UpdateNotificationRead>,
|
||||
) -> 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_notification_read(id, req.read, &user).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Notification updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
}
|
||||
}
|
|
@ -61,12 +61,10 @@ pub async fn create_request(
|
|||
|
||||
// create reaction
|
||||
match data
|
||||
.create_reaction(Reaction::new(
|
||||
user.id,
|
||||
asset_id,
|
||||
req.asset_type,
|
||||
req.is_like,
|
||||
))
|
||||
.create_reaction(
|
||||
Reaction::new(user.id, asset_id, req.asset_type, req.is_like),
|
||||
&user,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue