Skip to content

Commit

Permalink
added article feed to newspaper
Browse files Browse the repository at this point in the history
  • Loading branch information
PXNX committed Nov 26, 2023
1 parent 5e7aa30 commit b60c3a4
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 139 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition = "2021"
[profile.dev]
opt-level = 0

[profile.dev.package.askama_derive]
opt-level = 3

[profile.release]
opt-level = 3

Expand Down
7 changes: 0 additions & 7 deletions input.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,6 @@ img {
}


svg {
/* display: block; */

cursor: move;
touch-action: none;
}

#hud {
background: rgba(0, 0, 0, 0.6);
position: absolute;
Expand Down
145 changes: 31 additions & 114 deletions public/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -10317,8 +10317,8 @@ details.collapse summary::-webkit-details-marker {
height: 2.5rem !important;
}

.h-12 {
height: 3rem !important;
.h-2 {
height: 0.5rem !important;
}

.h-4 {
Expand All @@ -10333,22 +10333,14 @@ details.collapse summary::-webkit-details-marker {
height: 1.5rem !important;
}

.h-\[100dvh\] {
height: 100dvh !important;
}

.h-full {
height: 100% !important;
}

.h-2 {
height: 0.5rem !important;
}

.h-8 {
height: 2rem !important;
}

.h-\[100dvh\] {
height: 100dvh !important;
}

.min-h-screen {
min-height: 100vh !important;
}
Expand All @@ -10357,8 +10349,8 @@ details.collapse summary::-webkit-details-marker {
width: 0.25rem !important;
}

.w-12 {
width: 3rem !important;
.w-1\/2 {
width: 50% !important;
}

.w-4 {
Expand All @@ -10373,22 +10365,14 @@ details.collapse summary::-webkit-details-marker {
width: 1.5rem !important;
}

.w-full {
width: 100% !important;
}

.w-1\/2 {
width: 50% !important;
}

.w-3\/4 {
width: 75% !important;
}

.w-8 {
width: 2rem !important;
}

.w-full {
width: 100% !important;
}

.max-w-sm {
max-width: 24rem !important;
}
Expand Down Expand Up @@ -10737,10 +10721,6 @@ details.collapse summary::-webkit-details-marker {
grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

.grid-cols-3 {
grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
}

.grid-rows-3 {
grid-template-rows: repeat(3, minmax(0, 1fr)) !important;
}
Expand Down Expand Up @@ -10947,10 +10927,16 @@ details.collapse summary::-webkit-details-marker {
margin-left: calc(0.5rem * calc(1 - var(--tw-space-x-reverse))) !important;
}

.space-x-4 > :not([hidden]) ~ :not([hidden]) {
--tw-space-x-reverse: 0 !important;
margin-right: calc(1rem * var(--tw-space-x-reverse)) !important;
margin-left: calc(1rem * calc(1 - var(--tw-space-x-reverse))) !important;
.space-y-1 > :not([hidden]) ~ :not([hidden]) {
--tw-space-y-reverse: 0 !important;
margin-top: calc(0.25rem * calc(1 - var(--tw-space-y-reverse))) !important;
margin-bottom: calc(0.25rem * var(--tw-space-y-reverse)) !important;
}

.space-y-1\.5 > :not([hidden]) ~ :not([hidden]) {
--tw-space-y-reverse: 0 !important;
margin-top: calc(0.375rem * calc(1 - var(--tw-space-y-reverse))) !important;
margin-bottom: calc(0.375rem * var(--tw-space-y-reverse)) !important;
}

.space-y-2 > :not([hidden]) ~ :not([hidden]) {
Expand All @@ -10971,18 +10957,6 @@ details.collapse summary::-webkit-details-marker {
margin-bottom: calc(2rem * var(--tw-space-y-reverse)) !important;
}

.space-y-1 > :not([hidden]) ~ :not([hidden]) {
--tw-space-y-reverse: 0 !important;
margin-top: calc(0.25rem * calc(1 - var(--tw-space-y-reverse))) !important;
margin-bottom: calc(0.25rem * var(--tw-space-y-reverse)) !important;
}

.space-y-1\.5 > :not([hidden]) ~ :not([hidden]) {
--tw-space-y-reverse: 0 !important;
margin-top: calc(0.375rem * calc(1 - var(--tw-space-y-reverse))) !important;
margin-bottom: calc(0.375rem * var(--tw-space-y-reverse)) !important;
}

.space-y-reverse > :not([hidden]) ~ :not([hidden]) {
--tw-space-y-reverse: 1 !important;
}
Expand Down Expand Up @@ -11360,10 +11334,6 @@ details.collapse summary::-webkit-details-marker {
border-width: 1px !important;
}

.border-2 {
border-width: 2px !important;
}

.border-x {
border-left-width: 1px !important;
border-right-width: 1px !important;
Expand Down Expand Up @@ -11426,11 +11396,6 @@ details.collapse summary::-webkit-details-marker {
border-style: none !important;
}

.border-gray-200 {
--tw-border-opacity: 1 !important;
border-color: rgb(229 231 235 / var(--tw-border-opacity)) !important;
}

.border-primary {
--tw-border-opacity: 1 !important;
border-color: var(--fallback-p,oklch(var(--p)/var(--tw-border-opacity))) !important;
Expand All @@ -11451,11 +11416,6 @@ details.collapse summary::-webkit-details-marker {
background-color: rgb(255 0 0 / var(--tw-bg-opacity)) !important;
}

.bg-amber-300 {
--tw-bg-opacity: 1 !important;
background-color: rgb(252 211 77 / var(--tw-bg-opacity)) !important;
}

.bg-base-100 {
--tw-bg-opacity: 1 !important;
background-color: var(--fallback-b1,oklch(var(--b1)/var(--tw-bg-opacity))) !important;
Expand All @@ -11466,29 +11426,24 @@ details.collapse summary::-webkit-details-marker {
background-color: var(--fallback-b2,oklch(var(--b2)/var(--tw-bg-opacity))) !important;
}

.bg-blue-200 {
--tw-bg-opacity: 1 !important;
background-color: rgb(191 219 254 / var(--tw-bg-opacity)) !important;
}

.bg-blue-500 {
--tw-bg-opacity: 1 !important;
background-color: rgb(59 130 246 / var(--tw-bg-opacity)) !important;
}

.bg-gray-800 {
.bg-gray-200 {
--tw-bg-opacity: 1 !important;
background-color: rgb(31 41 55 / var(--tw-bg-opacity)) !important;
background-color: rgb(229 231 235 / var(--tw-bg-opacity)) !important;
}

.bg-green-400 {
.bg-gray-800 {
--tw-bg-opacity: 1 !important;
background-color: rgb(74 222 128 / var(--tw-bg-opacity)) !important;
background-color: rgb(31 41 55 / var(--tw-bg-opacity)) !important;
}

.bg-pink-500 {
.bg-green-500 {
--tw-bg-opacity: 1 !important;
background-color: rgb(236 72 153 / var(--tw-bg-opacity)) !important;
background-color: rgb(34 197 94 / var(--tw-bg-opacity)) !important;
}

.bg-primary {
Expand All @@ -11506,21 +11461,6 @@ details.collapse summary::-webkit-details-marker {
background-color: rgb(255 255 255 / var(--tw-bg-opacity)) !important;
}

.bg-gray-100 {
--tw-bg-opacity: 1 !important;
background-color: rgb(243 244 246 / var(--tw-bg-opacity)) !important;
}

.bg-gray-200 {
--tw-bg-opacity: 1 !important;
background-color: rgb(229 231 235 / var(--tw-bg-opacity)) !important;
}

.bg-green-500 {
--tw-bg-opacity: 1 !important;
background-color: rgb(34 197 94 / var(--tw-bg-opacity)) !important;
}

.bg-\[url\(\'https\:\/\/source\.unsplash\.com\/random\.jpg\?soldier\'\)\] {
background-image: url('https://source.unsplash.com/random.jpg?soldier') !important;
}
Expand Down Expand Up @@ -12288,12 +12228,6 @@ details.collapse summary::-webkit-details-marker {
transition-duration: 150ms !important;
}

.transition-shadow {
transition-property: box-shadow !important;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1) !important;
transition-duration: 150ms !important;
}

.duration-500 {
transition-duration: 500ms !important;
}
Expand Down Expand Up @@ -12362,12 +12296,6 @@ img {
justify-content: center;
}

svg {
/* display: block; */
cursor: move;
touch-action: none;
}

#hud {
background: rgba(0, 0, 0, 0.6);
position: absolute;
Expand Down Expand Up @@ -14077,12 +14005,6 @@ svg {
font-weight: 700 !important;
}

.hover\:shadow-md:hover {
--tw-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1) !important;
--tw-shadow-colored: 0 4px 6px -1px var(--tw-shadow-color), 0 2px 4px -2px var(--tw-shadow-color) !important;
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow) !important;
}

.before\:hover\:text-center:hover::before {
content: var(--tw-content) !important;
text-align: center !important;
Expand Down Expand Up @@ -14274,20 +14196,15 @@ svg {
border-color: rgb(55 65 81 / var(--tw-divide-opacity)) !important;
}

.dark\:bg-gray-900 {
--tw-bg-opacity: 1 !important;
background-color: rgb(17 24 39 / var(--tw-bg-opacity)) !important;
.dark\:text-gray-400 {
--tw-text-opacity: 1 !important;
color: rgb(156 163 175 / var(--tw-text-opacity)) !important;
}

.dark\:text-zinc-400 {
--tw-text-opacity: 1 !important;
color: rgb(161 161 170 / var(--tw-text-opacity)) !important;
}

.dark\:text-gray-400 {
--tw-text-opacity: 1 !important;
color: rgb(156 163 175 / var(--tw-text-opacity)) !important;
}
}

@media (min-width: 640px) {
Expand Down
51 changes: 50 additions & 1 deletion src/routes/newspaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@ use crate::common::tools::format_date;

use super::{AppState, UserData};

#[derive(Clone, Debug, Deserialize, Serialize)]
struct ArticlePreview {
id: i64,
title: String,
upvote_count: i64,
publish_date: String,
}

#[derive(Template)]
#[template(path = "newspaper/view.html")]
struct NewspaperTemplate {
newspaper_name: String,
newspaper_avatar: String,
newspaper_created_at: String,
//todo: add article feed of a newspaper
articles: Vec<ArticlePreview>,
owner_id: i64,
owner_name: String,
owner_avatar: String,
}

async fn newspaper(
Expand All @@ -44,10 +55,48 @@ async fn newspaper(
user_message: format!("No newspaper with id {newspaper_id} was found."),
})?;

let articles: Vec<ArticlePreview> = query!(
r#"SELECT articles.id,
articles.title,
articles.created_at,
COALESCE(uv.upvote_count,0) AS upvote_count
FROM articles
LEFT JOIN (SELECT article_id, count(*) upvote_count
FROM upvotes
GROUP BY article_id) as uv
ON uv.article_id = articles.id
where articles.newspaper_id = $1
ORDER BY articles.created_at DESC
LIMIT 30;"#,
&newspaper_id
)
.fetch_all(&db_pool)
.await?
.iter()
.map(|a| ArticlePreview {
id: a.id,
title: a.title.clone(),
publish_date: format_date(a.created_at),
upvote_count: a.upvote_count.unwrap(),
})
.collect();

let newspaper_owner = query!(
r#"SELECT id, name, avatar FROM users WHERE id in (select user_id from journalists where rank = 'owner' and newspaper_id = $1 )"#,
newspaper_id
)
.fetch_one(&db_pool)
.await?;

Ok(NewspaperTemplate {
newspaper_name: newspaper.name,
newspaper_avatar: newspaper.avatar,
newspaper_created_at: format_date(newspaper.created_at),
articles: articles,
owner_id: newspaper_owner.id,
owner_name: newspaper_owner.name.unwrap(),
owner_avatar: newspaper_owner.avatar.unwrap_or("".to_owned()),
})
}

Expand Down
4 changes: 2 additions & 2 deletions templates/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@


<div id="limit-div" style="width: 100%; height: 100%; border:1px solid black; ">
<svg id="limit-svg" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; display: inline; " width="100%"
height="100%" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink"
<svg id="limit-svg" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; display: inline; cursor: move;
touch-action: none; " width="100%" height="100%" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ev="http://www.w3.org/2001/xml-events" preserveAspectRatio="xMidYMid" viewBox='0 0 5632 2048'>

<g id="province" class="province">
Expand Down
Loading

0 comments on commit b60c3a4

Please sign in to comment.