Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBiscardi committed Feb 27, 2024
1 parent 8753851 commit 47d8098
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 169 deletions.
5 changes: 3 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::{
components::{AboutSection, TinyWaveFormIcon},
routes::{
admin::{self, AdminWrapper},
custom,
index::Home,
issue,
custom,
},
},
error_template::{AppError, ErrorTemplate},
Expand All @@ -23,7 +23,8 @@ pub fn App() -> impl IntoView {
// titles, meta tags, etc.
provide_meta_context();

let pkg_path: &'static str = std::option_env!("CDN_PKG_PATH").unwrap_or("/pkg");
let pkg_path: &'static str =
std::option_env!("CDN_PKG_PATH").unwrap_or("/pkg");
view! {
<Html
lang="en"
Expand Down
6 changes: 4 additions & 2 deletions src/app/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ pub fn TinyWaveFormIcon(
}

#[component]
pub fn Divider(#[prop(into)] title: String) -> impl IntoView {
pub fn Divider(
#[prop(into)] title: String,
) -> impl IntoView {
view! {
<div class="relative mt-12 mb-6">
<div class="absolute inset-0 flex items-center" aria-hidden="true">
Expand All @@ -96,4 +98,4 @@ pub fn Divider(#[prop(into)] title: String) -> impl IntoView {
</div>
</div>
}
}
}
2 changes: 1 addition & 1 deletion src/app/routes.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::app::components::Container;
use leptos::*;
pub mod admin;
pub mod custom;
pub mod index;
pub mod issue;
pub mod custom;

#[component]
fn PauseIcon(
Expand Down
10 changes: 4 additions & 6 deletions src/app/routes/admin.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use leptos::*;
use leptos_router::*;

pub mod issue;
pub mod issues;
pub mod showcase;
pub mod crate_release;
pub mod educational;
pub mod devlog;
pub mod educational;
pub mod image;
pub mod issue;
pub mod issues;
pub mod showcase;

#[component]
pub fn AdminHomepage() -> impl IntoView {
Expand Down Expand Up @@ -213,5 +213,3 @@ pub fn AdminWrapper() -> impl IntoView {
</div>
}
}


1 change: 0 additions & 1 deletion src/app/routes/admin/crate_release.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use leptos::*;


#[component]
pub fn CrateRelease() -> impl IntoView {
view! { <div>CrateRelease</div> }
Expand Down
3 changes: 1 addition & 2 deletions src/app/routes/admin/devlog.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use leptos::*;


#[component]
pub fn Devlog() -> impl IntoView {
view! { <div>Devlog</div> }
}
}
3 changes: 1 addition & 2 deletions src/app/routes/admin/educational.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use leptos::*;


#[component]
pub fn Educational() -> impl IntoView {
view! { <div>Educational</div> }
}
}
50 changes: 31 additions & 19 deletions src/app/routes/admin/image.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use leptos::*;
use crate::app::components::Divider;
use leptos_router::*;
use serde::{Deserialize, Serialize};
#[cfg(feature = "ssr")]
use crate::app::server_fn::error::NoCustomError;
use leptos::*;
use leptos_router::*;
use serde::{Deserialize, Serialize};
#[cfg(feature = "ssr")]
use tracing::error;

Expand Down Expand Up @@ -59,12 +59,10 @@ pub fn Image() -> impl IntoView {
}
}



#[server]
async fn add_image(
cloudinary_public_id: String,
description: String
description: String,
) -> Result<(), ServerFnError> {
let pool = crate::sql::pool()?;
let _username = crate::sql::with_admin_access()?;
Expand All @@ -90,7 +88,8 @@ async fn add_image(

#[component]
fn Images() -> impl IntoView {
let images = create_resource(move || {}, |_| fetch_images());
let images =
create_resource(move || {}, |_| fetch_images());

view! {
<Suspense fallback=move || {
Expand Down Expand Up @@ -128,7 +127,11 @@ fn Images() -> impl IntoView {
}

#[component]
fn ImageLi(id: String, url: String, description: String) -> impl IntoView {
fn ImageLi(
id: String,
url: String,
description: String,
) -> impl IntoView {
view! {
<li class="relative">
<div class="group aspect-h-7 aspect-w-10 block w-full overflow-hidden rounded-lg bg-gray-100 focus-within:ring-2 focus-within:ring-indigo-500 focus-within:ring-offset-2 focus-within:ring-offset-gray-100">
Expand All @@ -154,25 +157,33 @@ fn ImageLi(id: String, url: String, description: String) -> impl IntoView {
struct SqlImage {
id: Vec<u8>,
description: String,
cloudinary_public_id: String
cloudinary_public_id: String,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct Image {
pub id: String,
pub description: String,
pub url: String
pub url: String,
}

#[cfg(feature = "ssr")]
impl From<SqlImage> for Image {
fn from(value: SqlImage) -> Self {
use cloudinary::transformation::{
Transformations::Resize, resize_mode::ResizeMode::ScaleByWidth, Image as CImage
resize_mode::ResizeMode::ScaleByWidth,
Image as CImage, Transformations::Resize,
};

let image = CImage::new("dilgcuzda".into(), value.cloudinary_public_id.into())
.add_transformation(Resize(ScaleByWidth{ width:300, ar: None, liquid:None }));

let image = CImage::new(
"dilgcuzda".into(),
value.cloudinary_public_id.into(),
)
.add_transformation(Resize(ScaleByWidth {
width: 300,
ar: None,
liquid: None,
}));

let id_str =
rusty_ulid::Ulid::try_from(value.id.as_slice())
Expand All @@ -182,15 +193,14 @@ impl From<SqlImage> for Image {
Image {
id: id_str.to_string(),
description: value.description,
url: image.to_string()
url: image.to_string(),
}
}
}


#[server]
async fn fetch_images(
) -> Result<Vec<Image>, ServerFnError> {
async fn fetch_images() -> Result<Vec<Image>, ServerFnError>
{
let pool = crate::sql::pool()?;
let _username = crate::sql::with_admin_access()?;

Expand All @@ -208,7 +218,9 @@ limit 5"#
.await
.map_err(|e| {
error!(?e);
ServerFnError::<NoCustomError>::ServerError("sql failed".to_string())
ServerFnError::<NoCustomError>::ServerError(
"sql failed".to_string(),
)
})?;

Ok(images.into_iter().map(Image::from).collect())
Expand Down
21 changes: 13 additions & 8 deletions src/app/routes/admin/issue.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::app::components::Divider;
use leptos::*;
use leptos_router::*;
use serde::{Deserialize, Serialize};
use crate::app::components::{Divider};

#[component]
pub fn Issue() -> impl IntoView {
Expand Down Expand Up @@ -293,7 +293,7 @@ fn Showcases() -> impl IntoView {
},
fetch_showcases_for_issue_id,
);

view! {
<ul
role="list"
Expand Down Expand Up @@ -372,22 +372,21 @@ fn ShowcaseLi(showcase: ShowcaseData) -> impl IntoView {
}
}


#[cfg(feature = "ssr")]
#[derive(Debug, sqlx::FromRow)]
struct SqlShowcaseData {
id: Vec<u8>,
title: String,
posted_date: Option<time::Date>,
image_count: Option<i64>
image_count: Option<i64>,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct ShowcaseData {
pub id: String,
pub title: String,
pub posted_date: Option<time::Date>,
pub image_count: u32
pub image_count: u32,
}

#[cfg(feature = "ssr")]
Expand All @@ -402,14 +401,17 @@ impl From<SqlShowcaseData> for ShowcaseData {
id: id_str.to_string(),
title: value.title,
posted_date: value.posted_date,
image_count: value.image_count.unwrap_or_default() as u32
image_count: value
.image_count
.unwrap_or_default()
as u32,
}
}
}

#[server]
pub async fn fetch_showcases_for_issue_id(
issue_id: String
issue_id: String,
) -> Result<Vec<ShowcaseData>, ServerFnError> {
let pool = crate::sql::pool()?;
let _username = crate::sql::with_admin_access()?;
Expand Down Expand Up @@ -441,5 +443,8 @@ issue_id.as_slice()
.fetch_all(&pool)
.await?;

Ok(showcases.into_iter().map(ShowcaseData::from).collect())
Ok(showcases
.into_iter()
.map(ShowcaseData::from)
.collect())
}
31 changes: 20 additions & 11 deletions src/app/routes/admin/showcase.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use leptos::*;
use leptos_router::*;
use serde::{Serialize, Deserialize};
use crate::app::components::Divider;
use futures::future::join;
use leptos::*;
use leptos_router::*;
use serde::{Deserialize, Serialize};
pub mod id;

#[server]
Expand Down Expand Up @@ -42,8 +42,10 @@ async fn add_showcase(
pub fn Showcase() -> impl IntoView {
let add_showcase =
create_server_action::<AddShowcase>();
let showcases =
create_resource(move || {}, |_| join(fetch_showcases(), fetch_issues()));
let showcases = create_resource(
move || {},
|_| join(fetch_showcases(), fetch_issues()),
);

view! {
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8">
Expand Down Expand Up @@ -166,8 +168,13 @@ pub fn Showcase() -> impl IntoView {
}

#[component]
fn AddShowcaseToIssueForm(showcase: ShowcaseData, issue_id: Option<String>) -> impl IntoView {
let associate_showcase_with_issue = create_server_action::<AssociateShowcaseWithIssue>();
fn AddShowcaseToIssueForm(
showcase: ShowcaseData,
issue_id: Option<String>,
) -> impl IntoView {
let associate_showcase_with_issue =
create_server_action::<AssociateShowcaseWithIssue>(
);

view! {
<li class="flex items-center justify-between gap-x-6 py-5">
Expand Down Expand Up @@ -264,7 +271,10 @@ ORDER BY showcase.id"
.fetch_all(&pool)
.await?;

Ok(showcases.into_iter().map(ShowcaseData::from).collect())
Ok(showcases
.into_iter()
.map(ShowcaseData::from)
.collect())
}

#[server]
Expand Down Expand Up @@ -300,7 +310,6 @@ async fn associate_showcase_with_issue(
Ok(())
}


#[cfg(feature = "ssr")]
#[derive(Debug, sqlx::FromRow)]
struct SqlIssueShort {
Expand All @@ -324,7 +333,7 @@ impl From<SqlIssueShort> for IssueShort {
);
IssueShort {
id: id_str.to_string(),
display_name: value.display_name
display_name: value.display_name,
}
}
}
Expand All @@ -348,4 +357,4 @@ ORDER BY issue_date DESC"#
.await?;

Ok(issues.into_iter().map(IssueShort::from).collect())
}
}
Loading

0 comments on commit 47d8098

Please sign in to comment.