nebo něco
Tento commit je obsažen v:
rodič
1052f7c926
revize
a96c86a722
@ -54,8 +54,8 @@ pub fn check_page(
|
|||||||
ext = "html",
|
ext = "html",
|
||||||
source = "{% import \"./macros/post.html\" as post %}{% call post::post(board, post, post.thread.is_some()) %}"
|
source = "{% import \"./macros/post.html\" as post %}{% call post::post(board, post, post.thread.is_some()) %}"
|
||||||
)]
|
)]
|
||||||
pub struct PostTemplate {
|
pub struct PostTemplate<'a> {
|
||||||
tcx: TemplateCtx,
|
tcx: &'a TemplateCtx,
|
||||||
post: Post,
|
board: &'a Board,
|
||||||
board: Board,
|
post: &'a Post,
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,8 @@ use uuid::Uuid;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::models::{Board, Post},
|
db::models::{Board, Post},
|
||||||
web::tcx::TemplateCtx, PostTemplate,
|
web::tcx::TemplateCtx,
|
||||||
|
PostTemplate,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Message)]
|
#[derive(Message)]
|
||||||
@ -144,12 +145,12 @@ impl Handler<PostCreatedMessage> for LiveHub {
|
|||||||
|
|
||||||
tcx.update_yous(&mut self.cache).ok();
|
tcx.update_yous(&mut self.cache).ok();
|
||||||
|
|
||||||
let post = post.clone();
|
let tcx = &tcx;
|
||||||
|
let board = &board;
|
||||||
|
let post = &post;
|
||||||
let id = post.id;
|
let id = post.id;
|
||||||
let tcx = tcx.clone();
|
|
||||||
let board = board.clone();
|
|
||||||
|
|
||||||
let html = PostTemplate { tcx, post, board }
|
let html = PostTemplate { tcx, board, post }
|
||||||
.render()
|
.render()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
@ -175,9 +176,11 @@ impl Handler<TargetedPostCreatedMessage> for LiveHub {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let id = post.id;
|
let id = post.id;
|
||||||
let tcx = tcx.clone();
|
let tcx = &tcx;
|
||||||
|
let board = &board;
|
||||||
|
let post = &post;
|
||||||
|
|
||||||
let html = PostTemplate { tcx, post, board }
|
let html = PostTemplate { tcx, board, post }
|
||||||
.render()
|
.render()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
@ -213,10 +216,10 @@ impl Handler<PostUpdatedMessage> for LiveHub {
|
|||||||
|
|
||||||
tcx.update_yous(&mut self.cache).ok();
|
tcx.update_yous(&mut self.cache).ok();
|
||||||
|
|
||||||
let post = post.clone();
|
|
||||||
let id = post.id;
|
let id = post.id;
|
||||||
let tcx = tcx.clone();
|
let tcx = &tcx;
|
||||||
let board = board.clone();
|
let board = &board;
|
||||||
|
let post = &post;
|
||||||
|
|
||||||
let html = PostTemplate { tcx, post, board }
|
let html = PostTemplate { tcx, post, board }
|
||||||
.render()
|
.render()
|
||||||
|
@ -73,7 +73,7 @@ async fn run() -> Result<(), Error> {
|
|||||||
.service(web::news::news)
|
.service(web::news::news)
|
||||||
.service(web::overboard::overboard)
|
.service(web::overboard::overboard)
|
||||||
.service(web::overboard_catalog::overboard_catalog)
|
.service(web::overboard_catalog::overboard_catalog)
|
||||||
.service(web::post_json::post_json)
|
.service(web::thread_json::thread_json)
|
||||||
.service(web::thread::thread)
|
.service(web::thread::thread)
|
||||||
.service(web::actions::appeal_ban::appeal_ban)
|
.service(web::actions::appeal_ban::appeal_ban)
|
||||||
.service(web::actions::create_post::create_post)
|
.service(web::actions::create_post::create_post)
|
||||||
|
@ -11,7 +11,7 @@ pub mod logout;
|
|||||||
pub mod news;
|
pub mod news;
|
||||||
pub mod overboard;
|
pub mod overboard;
|
||||||
pub mod overboard_catalog;
|
pub mod overboard_catalog;
|
||||||
pub mod post_json;
|
pub mod thread_json;
|
||||||
pub mod staff;
|
pub mod staff;
|
||||||
pub mod tcx;
|
pub mod tcx;
|
||||||
pub mod thread;
|
pub mod thread;
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
use actix_web::{
|
|
||||||
get,
|
|
||||||
web::{Data, Json, Path},
|
|
||||||
HttpRequest,
|
|
||||||
};
|
|
||||||
use askama::Template;
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
ctx::Ctx,
|
|
||||||
db::models::{Board, Post},
|
|
||||||
error::NekrochanError,
|
|
||||||
web::tcx::TemplateCtx,
|
|
||||||
PostTemplate,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
pub struct PostJsonResponse {
|
|
||||||
pub html: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/post-json/{board}/{id}")]
|
|
||||||
pub async fn post_json(
|
|
||||||
ctx: Data<Ctx>,
|
|
||||||
req: HttpRequest,
|
|
||||||
path: Path<(String, i64)>,
|
|
||||||
) -> Result<Json<PostJsonResponse>, NekrochanError> {
|
|
||||||
let (board, id) = path.into_inner();
|
|
||||||
|
|
||||||
let tcx = TemplateCtx::new(&ctx, &req).await?;
|
|
||||||
|
|
||||||
let board = Board::read(&ctx, board.clone())
|
|
||||||
.await?
|
|
||||||
.ok_or(NekrochanError::BoardNotFound(board))?;
|
|
||||||
|
|
||||||
let post = Post::read(&ctx, board.id.clone(), id)
|
|
||||||
.await?
|
|
||||||
.ok_or(NekrochanError::PostNotFound(board.id.clone(), id))?;
|
|
||||||
|
|
||||||
let html = PostTemplate { tcx, board, post }
|
|
||||||
.render()
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let res = PostJsonResponse { html };
|
|
||||||
|
|
||||||
Ok(Json(res))
|
|
||||||
}
|
|
58
src/web/thread_json.rs
Normální soubor
58
src/web/thread_json.rs
Normální soubor
@ -0,0 +1,58 @@
|
|||||||
|
use actix_web::{
|
||||||
|
get,
|
||||||
|
web::{Data, Json, Path},
|
||||||
|
HttpRequest,
|
||||||
|
};
|
||||||
|
use askama::Template;
|
||||||
|
use std::{collections::HashMap, vec};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
ctx::Ctx,
|
||||||
|
db::models::{Board, Post},
|
||||||
|
error::NekrochanError,
|
||||||
|
web::tcx::TemplateCtx,
|
||||||
|
PostTemplate,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[get("/thread-json/{board}/{id}")]
|
||||||
|
pub async fn thread_json(
|
||||||
|
ctx: Data<Ctx>,
|
||||||
|
req: HttpRequest,
|
||||||
|
path: Path<(String, i64)>,
|
||||||
|
) -> Result<Json<HashMap<i64, String>>, NekrochanError> {
|
||||||
|
let (board, id) = path.into_inner();
|
||||||
|
|
||||||
|
let tcx = TemplateCtx::new(&ctx, &req).await?;
|
||||||
|
|
||||||
|
let board = Board::read(&ctx, board.clone())
|
||||||
|
.await?
|
||||||
|
.ok_or(NekrochanError::BoardNotFound(board))?;
|
||||||
|
|
||||||
|
let thread = Post::read(&ctx, board.id.clone(), id)
|
||||||
|
.await?
|
||||||
|
.ok_or(NekrochanError::PostNotFound(board.id.clone(), id))?;
|
||||||
|
|
||||||
|
if thread.thread.is_some() {
|
||||||
|
return Err(NekrochanError::IsReplyError);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut res = HashMap::new();
|
||||||
|
|
||||||
|
let replies = thread.read_replies(&ctx).await?;
|
||||||
|
let posts = vec![vec![thread], replies].concat();
|
||||||
|
|
||||||
|
for post in posts {
|
||||||
|
let id = post.id;
|
||||||
|
let tcx = &tcx;
|
||||||
|
let board = &board;
|
||||||
|
let post = &post;
|
||||||
|
|
||||||
|
let html = PostTemplate { tcx, board, post }
|
||||||
|
.render()
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
res.insert(id, html);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Json(res))
|
||||||
|
}
|
@ -20,7 +20,7 @@ $(function () {
|
|||||||
setup_events($(".quote"));
|
setup_events($(".quote"));
|
||||||
|
|
||||||
function setup_events(elements) {
|
function setup_events(elements) {
|
||||||
elements.on("mouseenter", function (event) {
|
elements.on("mouseover", function (event) {
|
||||||
toggle_hover($(this), event);
|
toggle_hover($(this), event);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -36,34 +36,35 @@ $(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function toggle_hover(quote, event) {
|
function toggle_hover(quote, event) {
|
||||||
hovering = event.type === "mouseenter";
|
hovering = event.type === "mouseover";
|
||||||
|
|
||||||
let path_segments = quote.prop("pathname").split("/");
|
if ($("#preview").length !== 0 && !hovering) {
|
||||||
let board = path_segments[2];
|
|
||||||
let id = quote.prop("hash").slice(1);
|
|
||||||
|
|
||||||
let post = $(`#${id}[data-board="${board}"]`);
|
|
||||||
|
|
||||||
if (post.length > 0) {
|
|
||||||
if (post.isInViewport()) {
|
|
||||||
post.toggleClass("highlighted", hovering);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hovering) {
|
|
||||||
create_preview(post.clone(), event.clientX, event.clientY);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($("#preview").length > 0 && !hovering) {
|
|
||||||
remove_preview();
|
remove_preview();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let html = cache[`${board}/${id}`];
|
let path_segments = quote.prop("pathname").split("/");
|
||||||
|
let board = path_segments[2];
|
||||||
|
let thread = path_segments[3];
|
||||||
|
let id = quote.prop("hash").slice(1);
|
||||||
|
|
||||||
if (html) {
|
let post = $(`#${id}[data-board="${board}"]`);
|
||||||
|
|
||||||
|
if (post.length !== 0 && post.isInViewport()) {
|
||||||
|
post.toggleClass("highlighted", hovering);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (post.length !== 0 && hovering) {
|
||||||
|
create_preview(post.clone(), event.clientX, event.clientY);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let html;
|
||||||
|
let cached_thread = cache[`${board}/${thread}`];
|
||||||
|
|
||||||
|
if (cached_thread) {
|
||||||
|
html = cached_thread[id];
|
||||||
post = $($.parseHTML(html));
|
post = $($.parseHTML(html));
|
||||||
create_preview(post, event.clientX, event.clientY);
|
create_preview(post, event.clientX, event.clientY);
|
||||||
return;
|
return;
|
||||||
@ -72,15 +73,13 @@ $(function () {
|
|||||||
quote.css("cursor", "wait");
|
quote.css("cursor", "wait");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$.get(`/post-json/${board}/${id}`, function (data) {
|
$.get(`/thread-json/${board}/${thread}`, function (data) {
|
||||||
quote.css("cursor", "");
|
quote.css("cursor", "");
|
||||||
|
cache[`${board}/${thread}`] = data;
|
||||||
html = data.html;
|
html = data[id];
|
||||||
cache[`${board}/${id}`] = html;
|
|
||||||
post = $($.parseHTML(html));
|
post = $($.parseHTML(html));
|
||||||
|
|
||||||
if (hovering)
|
create_preview(post, event.clientX, event.clientY);
|
||||||
create_preview(post, event.clientX, event.clientY);
|
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
quote.css("cursor", "");
|
quote.css("cursor", "");
|
||||||
@ -93,6 +92,10 @@ $(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function create_preview(preview, x, y) {
|
function create_preview(preview, x, y) {
|
||||||
|
if (!hovering) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
preview.attr("id", "preview");
|
preview.attr("id", "preview");
|
||||||
preview.addClass("box");
|
preview.addClass("box");
|
||||||
preview.removeClass("highlighted");
|
preview.removeClass("highlighted");
|
||||||
@ -100,7 +103,7 @@ $(function () {
|
|||||||
|
|
||||||
let existing = $("#preview");
|
let existing = $("#preview");
|
||||||
|
|
||||||
if (existing.length > 0) {
|
if (existing.length !== 0) {
|
||||||
existing.replaceWith(preview);
|
existing.replaceWith(preview);
|
||||||
} else {
|
} else {
|
||||||
preview.appendTo("body");
|
preview.appendTo("body");
|
||||||
|
Načítá se…
Odkázat v novém úkolu
Zablokovat Uživatele