tangled
alpha
login
or
join now
eldridge.cam
/
cartography
0
fork
atom
Trading card city builder game?
0
fork
atom
overview
issues
pulls
pipelines
refactor api and dtos
eldridge.cam
1 month ago
0b1768bb
ae833be7
verified
This commit was signed with the committer's
known signature
.
eldridge.cam
SSH Key Fingerprint:
SHA256:MAgO4sya2MgvdgUjSGKAO0lQ9X2HQp1Jb+x/Tpeeims=
0/0
Waiting for spindle ...
+44
-42
7 changed files
expand all
collapse all
unified
split
src
api
list_card_types.rs
mod.rs
app
cards.rs
components
card_grid.rs
mod.rs
dto
mod.rs
main.rs
+1
-26
src/api.rs
src/api/list_card_types.rs
···
1
1
-
use crate::db::TileCategory;
2
1
use dioxus::prelude::*;
3
3
-
use serde::{Deserialize, Serialize};
4
4
-
5
5
-
pub mod ws;
6
6
-
7
7
-
#[derive(Serialize, Deserialize, PartialEq, Clone)]
8
8
-
#[serde(tag = "class")]
9
9
-
pub enum CardType {
10
10
-
Tile(TileType),
11
11
-
Citizen(Species),
12
12
-
}
13
13
-
14
14
-
#[derive(Serialize, Deserialize, PartialEq, Clone)]
15
15
-
pub struct TileType {
16
16
-
pub id: String,
17
17
-
pub card_set_id: String,
18
18
-
pub category: TileCategory,
19
19
-
pub houses: i32,
20
20
-
pub employs: i32,
21
21
-
}
22
22
-
23
23
-
#[derive(Serialize, Deserialize, PartialEq, Clone)]
24
24
-
pub struct Species {
25
25
-
pub id: String,
26
26
-
pub card_set_id: String,
27
27
-
}
2
2
+
use crate::dto::*;
28
3
29
4
#[post("/api/cardtypes", db: axum::Extension<sqlx::PgPool>)]
30
5
pub async fn list_card_types() -> dioxus::Result<Vec<CardType>> {
+2
src/api/mod.rs
···
1
1
+
pub mod list_card_types;
2
2
+
pub mod ws;
+13
-13
src/app/cards.rs
···
1
1
-
use crate::api::list_card_types;
2
2
-
use crate::app::components::card_grid::CardGrid;
1
1
+
use crate::api::list_card_types::list_card_types;
3
2
use crate::app::Route;
3
3
+
use crate::app::components::card_grid::CardGrid;
4
4
use dioxus::prelude::*;
5
5
6
6
#[manganis::css_module("src/app/cards.css")]
···
8
8
9
9
#[component]
10
10
pub fn Cards() -> Element {
11
11
-
let cards = use_loader(list_card_types)?;
12
12
-
rsx! {
13
13
-
div { class: Css::gridarea,
14
14
-
CardGrid { cards: cards() }
15
15
-
}
16
16
-
}
17
17
-
}
18
18
-
19
19
-
#[component]
20
20
-
pub fn CardsLayout() -> Element {
21
11
rsx! {
22
12
main { class: Css::layout,
23
13
div { class: Css::controls,
···
27
17
}
28
18
}
29
19
ErrorBoundary { handle_error: |_| rsx! { "Failed to load cards, reload to try again" },
30
30
-
SuspenseBoundary { fallback: |_| rsx! { "Cards loading" }, Outlet::<Route> {} }
20
20
+
SuspenseBoundary { fallback: |_| rsx! { "Cards loading" }, CardsContent {} }
31
21
}
32
22
}
33
23
}
34
24
}
25
25
+
26
26
+
#[component]
27
27
+
fn CardsContent() -> Element {
28
28
+
let cards = use_loader(list_card_types)?;
29
29
+
rsx! {
30
30
+
div { class: Css::gridarea,
31
31
+
CardGrid { cards: cards() }
32
32
+
}
33
33
+
}
34
34
+
}
+2
-1
src/app/components/card_grid.rs
···
1
1
-
use crate::{api::CardType, db::TileCategory};
1
1
+
use crate::db::TileCategory;
2
2
+
use crate::dto::CardType;
2
3
use dioxus::prelude::*;
3
4
4
5
#[manganis::css_module("src/app/components/card_grid.css")]
+1
-2
src/app/mod.rs
···
6
6
mod menu;
7
7
mod play;
8
8
9
9
-
use cards::{Cards, CardsLayout};
9
9
+
use cards::Cards;
10
10
use menu::Menu;
11
11
use play::Play;
12
12
···
16
16
enum Route {
17
17
#[route("/")]
18
18
Menu {},
19
19
-
#[layout(CardsLayout)]
20
19
#[route("/cards")]
21
20
Cards {},
22
21
#[route("/play")]
+24
src/dto/mod.rs
···
1
1
+
use crate::db::TileCategory;
2
2
+
use serde::{Deserialize, Serialize};
3
3
+
4
4
+
#[derive(Serialize, Deserialize, PartialEq, Clone)]
5
5
+
#[serde(tag = "class")]
6
6
+
pub enum CardType {
7
7
+
Tile(TileType),
8
8
+
Citizen(Species),
9
9
+
}
10
10
+
11
11
+
#[derive(Serialize, Deserialize, PartialEq, Clone)]
12
12
+
pub struct TileType {
13
13
+
pub id: String,
14
14
+
pub card_set_id: String,
15
15
+
pub category: TileCategory,
16
16
+
pub houses: i32,
17
17
+
pub employs: i32,
18
18
+
}
19
19
+
20
20
+
#[derive(Serialize, Deserialize, PartialEq, Clone)]
21
21
+
pub struct Species {
22
22
+
pub id: String,
23
23
+
pub card_set_id: String,
24
24
+
}
+1
src/main.rs
···
2
2
mod api;
3
3
mod app;
4
4
mod db;
5
5
+
mod dto;
5
6
6
7
use crate::app::App;
7
8