add: popular questions timeline
This commit is contained in:
parent
424c823926
commit
d6c7372610
6 changed files with 100 additions and 1 deletions
|
@ -66,6 +66,8 @@ pub const TIMELINES_FOLLOWING: &str = include_str!("./public/html/timelines/foll
|
|||
pub const TIMELINES_ALL: &str = include_str!("./public/html/timelines/all.html");
|
||||
pub const TIMELINES_HOME_QUESTIONS: &str =
|
||||
include_str!("./public/html/timelines/home_questions.html");
|
||||
pub const TIMELINES_POPULAR_QUESTIONS: &str =
|
||||
include_str!("./public/html/timelines/popular_questions.html");
|
||||
pub const TIMELINES_FOLLOWING_QUESTIONS: &str =
|
||||
include_str!("./public/html/timelines/following_questions.html");
|
||||
pub const TIMELINES_ALL_QUESTIONS: &str =
|
||||
|
@ -207,6 +209,7 @@ pub(crate) async fn write_assets(config: &Config) -> PathBufD {
|
|||
write_template!(html_path->"timelines/following.html"(crate::assets::TIMELINES_FOLLOWING) --config=config);
|
||||
write_template!(html_path->"timelines/all.html"(crate::assets::TIMELINES_ALL) --config=config);
|
||||
write_template!(html_path->"timelines/home_questions.html"(crate::assets::TIMELINES_HOME_QUESTIONS) --config=config);
|
||||
write_template!(html_path->"timelines/popular_questions.html"(crate::assets::TIMELINES_POPULAR_QUESTIONS) --config=config);
|
||||
write_template!(html_path->"timelines/following_questions.html"(crate::assets::TIMELINES_FOLLOWING_QUESTIONS) --config=config);
|
||||
write_template!(html_path->"timelines/all_questions.html"(crate::assets::TIMELINES_ALL_QUESTIONS) --config=config);
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
<title>Popular - {{ config.name }}</title>
|
||||
{% endblock %} {% block body %} {{ macros::nav(selected="popular") }}
|
||||
<main class="flex flex-col gap-2">
|
||||
{{ macros::timelines_nav(selected="popular") }}
|
||||
{{ macros::timelines_nav(selected="popular") }} {{
|
||||
macros::timelines_secondary_nav(posts="/popular",
|
||||
questions="/popular/questions") }}
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
<div class="card w-full flex flex-col gap-2">
|
||||
|
|
18
crates/app/src/public/html/timelines/popular_questions.html
Normal file
18
crates/app/src/public/html/timelines/popular_questions.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
{% extends "root.html" %} {% block head %}
|
||||
<title>Popular (questions) - {{ config.name }}</title>
|
||||
{% endblock %} {% block body %} {{ macros::nav() }}
|
||||
<main class="flex flex-col gap-2">
|
||||
{{ macros::timelines_nav(selected="popular") }} {{
|
||||
macros::timelines_secondary_nav(posts="/popular",
|
||||
questions="/popular/questions", selected="popular") }}
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
<div class="card w-full flex flex-col gap-2">
|
||||
{% for question in list %}
|
||||
{{ components::global_question(question=question, can_manage_questions=false, secondary=true) }}
|
||||
{% endfor %}
|
||||
|
||||
{{ components::pagination(page=page, items=list|length) }}
|
||||
</div>
|
||||
</main>
|
||||
{% endblock %}
|
|
@ -196,6 +196,44 @@ pub async fn index_questions_request(
|
|||
)
|
||||
}
|
||||
|
||||
/// `/popular/questions`
|
||||
pub async fn popular_questions_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Query(req): Query<PaginatedQuery>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => {
|
||||
return Html(render_error(Error::NotAllowed, &jar, &data, &None).await);
|
||||
}
|
||||
};
|
||||
|
||||
let list = match data
|
||||
.0
|
||||
.get_popular_global_questions(12, req.page, 604_800_000)
|
||||
.await
|
||||
{
|
||||
Ok(l) => match data.0.fill_questions(l).await {
|
||||
Ok(l) => l,
|
||||
Err(e) => return Html(render_error(e, &jar, &data, &Some(user)).await),
|
||||
},
|
||||
Err(e) => return Html(render_error(e, &jar, &data, &Some(user)).await),
|
||||
};
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
|
||||
|
||||
context.insert("list", &list);
|
||||
context.insert("page", &req.page);
|
||||
Html(
|
||||
data.1
|
||||
.render("timelines/popular_questions.html", &context)
|
||||
.unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
/// `/following/questions`
|
||||
pub async fn following_questions_request(
|
||||
jar: CookieJar,
|
||||
|
|
|
@ -23,6 +23,7 @@ pub fn routes() -> Router {
|
|||
.route("/all", get(misc::all_request))
|
||||
// question timelines
|
||||
.route("/questions", get(misc::index_questions_request))
|
||||
.route("/popular/questions", get(misc::popular_questions_request))
|
||||
.route(
|
||||
"/following/questions",
|
||||
get(misc::following_questions_request),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue