···11+[application]
22+33+[web.app]
44+55+# HTML title tag content
66+title = "Cartography"
77+88+# include `assets` in web platform
99+[web.resource]
1010+1111+# Additional CSS style files
1212+style = []
1313+1414+# Additional JavaScript files
1515+script = []
1616+1717+[web.resource.dev]
1818+1919+# Javascript code file
2020+# serve: [dev-server] only
2121+script = []
+24-2
README.md
···11-# Cartography?
11+# Development
22+33+Your new bare-bones project includes minimal organization with a single `main.rs` file and a few assets.
44+55+```
66+project/
77+├─ assets/ # Any assets that are used by the app should be placed here
88+├─ src/
99+│ ├─ main.rs # main.rs is the entry point to your application and currently contains all components for the app
1010+├─ Cargo.toml # The Cargo.toml file defines the dependencies and feature flags for your project
1111+```
21233-A trading card city builder game? Or something.
1313+### Serving Your App
1414+1515+Run the following command in the root of your project to start developing with the default platform:
1616+1717+```bash
1818+dx serve --platform web
1919+```
2020+2121+To run for a different platform, use the `--platform platform` flag. E.g.
2222+```bash
2323+dx serve --platform desktop
2424+```
2525+
···11-# API
22-33-This crate contains all shared fullstack server functions. This is a great place to place any server-only logic you would like to expose in multiple platforms like a method that accesses your database or a method that sends an email.
44-55-This crate will be built twice:
66-1. Once for the server build with the `dioxus/server` feature enabled
77-2. Once for the client build with the client feature disabled
88-99-During the server build, the server functions will be collected and hosted on a public API for the client to call. During the client build, the server functions will be compiled into the client build.
1010-1111-## Dependencies
1212-1313-Most server dependencies (like sqlx and tokio) will not compile on client platforms like WASM. To avoid building server dependencies on the client, you should add platform specific dependencies under the `server` feature in the [Cargo.toml](../Cargo.toml) file. More details about managing server only dependencies can be found in the [Dioxus guide](https://dioxuslabs.com/learn/0.7/guides/fullstack/managing_dependencies#adding-server-only-dependencies).
-8
packages/api/src/lib.rs
···11-//! This crate contains all shared fullstack server functions.
22-use dioxus::prelude::*;
33-44-/// Echo the user input on the server.
55-#[post("/api/echo")]
66-pub async fn echo(input: String) -> Result<String, ServerFnError> {
77- Ok(input)
88-}
···11-# Development
22-33-The desktop crate defines the entrypoint for the desktop app along with any assets, components and dependencies that are specific to desktop builds. The desktop crate starts out something like this:
44-55-```
66-desktop/
77-├─ assets/ # Assets used by the desktop app - Any platform specific assets should go in this folder
88-├─ src/
99-│ ├─ main.rs # The entrypoint for the desktop app.It also defines the routes for the desktop platform
1010-│ ├─ views/ # The views each route will render in the desktop version of the app
1111-│ │ ├─ mod.rs # Defines the module for the views route and re-exports the components for each route
1212-│ │ ├─ blog.rs # The component that will render at the /blog/:id route
1313-│ │ ├─ home.rs # The component that will render at the / route
1414-├─ Cargo.toml # The desktop crate's Cargo.toml - This should include all desktop specific dependencies
1515-```
1616-1717-## Dependencies
1818-Since you have fullstack enabled, the desktop crate will be built two times:
1919-1. Once for the server build with the `server` feature enabled
2020-2. Once for the client build with the `desktop` feature enabled
2121-2222-You should make all desktop specific dependencies optional and only enabled in the `desktop` feature. This will ensure that the server builds don't pull in desktop specific dependencies which cuts down on build times significantly.
2323-2424-### Serving Your Desktop App
2525-2626-You can start your desktop app with the following command:
2727-2828-```bash
2929-dx serve
3030-```
···11-use dioxus::prelude::*;
22-33-use ui::Navbar;
44-use views::{Blog, Home};
55-66-mod views;
77-88-#[derive(Debug, Clone, Routable, PartialEq)]
99-#[rustfmt::skip]
1010-enum Route {
1111- #[layout(DesktopNavbar)]
1212- #[route("/")]
1313- Home {},
1414- #[route("/blog/:id")]
1515- Blog { id: i32 },
1616-}
1717-1818-const MAIN_CSS: Asset = asset!("/assets/main.css");
1919-2020-fn main() {
2121- dioxus::launch(App);
2222-}
2323-2424-#[component]
2525-fn App() -> Element {
2626- // Build cool things ✌️
2727-2828- rsx! {
2929- // Global app resources
3030- document::Link { rel: "stylesheet", href: MAIN_CSS }
3131-3232- Router::<Route> {}
3333- }
3434-}
3535-3636-/// A desktop-specific Router around the shared `Navbar` component
3737-/// which allows us to use the desktop-specific `Route` enum.
3838-#[component]
3939-fn DesktopNavbar() -> Element {
4040- rsx! {
4141- Navbar {
4242- Link {
4343- to: Route::Home {},
4444- "Home"
4545- }
4646- Link {
4747- to: Route::Blog { id: 1 },
4848- "Blog"
4949- }
5050- }
5151-5252- Outlet::<Route> {}
5353- }
5454-}
-30
packages/desktop/src/views/blog.rs
···11-use crate::Route;
22-use dioxus::prelude::*;
33-44-const BLOG_CSS: Asset = asset!("/assets/blog.css");
55-66-#[component]
77-pub fn Blog(id: i32) -> Element {
88- rsx! {
99- document::Link { rel: "stylesheet", href: BLOG_CSS}
1010-1111- div {
1212- id: "blog",
1313-1414- // Content
1515- h1 { "This is blog #{id}!" }
1616- p { "In blog #{id}, we show how the Dioxus router works and how URL parameters can be passed as props to our route components." }
1717-1818- // Navigation links
1919- Link {
2020- to: Route::Blog { id: id - 1 },
2121- "Previous"
2222- }
2323- span { " <---> " }
2424- Link {
2525- to: Route::Blog { id: id + 1 },
2626- "Next"
2727- }
2828- }
2929- }
3030-}
···11-# Development
22-33-The mobile crate defines the entrypoint for the mobile app along with any assets, components and dependencies that are specific to mobile builds. The mobile crate starts out something like this:
44-55-```
66-mobile/
77-├─ assets/ # Assets used by the mobile app - Any platform specific assets should go in this folder
88-├─ src/
99-│ ├─ main.rs # The entrypoint for the mobile app.It also defines the routes for the mobile platform
1010-│ ├─ views/ # The views each route will render in the mobile version of the app
1111-│ │ ├─ mod.rs # Defines the module for the views route and re-exports the components for each route
1212-│ │ ├─ blog.rs # The component that will render at the /blog/:id route
1313-│ │ ├─ home.rs # The component that will render at the / route
1414-├─ Cargo.toml # The mobile crate's Cargo.toml - This should include all mobile specific dependencies
1515-```
1616-1717-## Dependencies
1818-Since you have fullstack enabled, the mobile crate will be built two times:
1919-1. Once for the server build with the `server` feature enabled
2020-2. Once for the client build with the `mobile` feature enabled
2121-2222-You should make all mobile specific dependencies optional and only enabled in the `mobile` feature. This will ensure that the server builds don't pull in mobile specific dependencies which cuts down on build times significantly.
2323-2424-### Serving Your Mobile App
2525-2626-Mobile platforms are shared in a single crate. To serve mobile, you need to explicitly set your target device to `android` or `ios`:
2727-2828-```bash
2929-dx serve --platform android
3030-```
···11-use dioxus::prelude::*;
22-33-use ui::Navbar;
44-use views::{Blog, Home};
55-66-mod views;
77-88-#[derive(Debug, Clone, Routable, PartialEq)]
99-#[rustfmt::skip]
1010-enum Route {
1111- #[layout(MobileNavbar)]
1212- #[route("/")]
1313- Home {},
1414- #[route("/blog/:id")]
1515- Blog { id: i32 },
1616-}
1717-1818-const MAIN_CSS: Asset = asset!("/assets/main.css");
1919-2020-fn main() {
2121- dioxus::launch(App);
2222-}
2323-2424-#[component]
2525-fn App() -> Element {
2626- // Build cool things ✌️
2727-2828- rsx! {
2929- // Global app resources
3030- document::Link { rel: "stylesheet", href: MAIN_CSS }
3131-3232- Router::<Route> {}
3333- }
3434-}
3535-3636-/// A mobile-specific Router around the shared `Navbar` component
3737-/// which allows us to use the mobile-specific `Route` enum.
3838-#[component]
3939-fn MobileNavbar() -> Element {
4040- rsx! {
4141- Navbar {
4242- Link {
4343- to: Route::Home {},
4444- "Home"
4545- }
4646- Link {
4747- to: Route::Blog { id: 1 },
4848- "Blog"
4949- }
5050- }
5151-5252- Outlet::<Route> {}
5353- }
5454-}
-30
packages/mobile/src/views/blog.rs
···11-use crate::Route;
22-use dioxus::prelude::*;
33-44-const BLOG_CSS: Asset = asset!("/assets/blog.css");
55-66-#[component]
77-pub fn Blog(id: i32) -> Element {
88- rsx! {
99- document::Link { rel: "stylesheet", href: BLOG_CSS}
1010-1111- div {
1212- id: "blog",
1313-1414- // Content
1515- h1 { "This is blog #{id}!" }
1616- p { "In blog #{id}, we show how the Dioxus router works and how URL parameters can be passed as props to our route components." }
1717-1818- // Navigation links
1919- Link {
2020- to: Route::Blog { id: id - 1 },
2121- "Previous"
2222- }
2323- span { " <---> " }
2424- Link {
2525- to: Route::Blog { id: id + 1 },
2626- "Next"
2727- }
2828- }
2929- }
3030-}
···11-# UI
22-33-This crate contains all shared components for the workspace. This is a great place to place any UI you would like to use in multiple platforms like a common `Button` or `Navbar` component.
44-55-```
66-ui/
77-├─ src/
88-│ ├─ lib.rs # The entrypoint for the ui crate
99-│ ├─ hero.rs # The Hero component that will be used in every platform
1010-│ ├─ echo.rs # The shared echo component that communicates with the server
1111-│ ├─ navbar.rs # The Navbar component that will be used in the layout of every platform's router
1212-```
1313-1414-## Dependencies
1515-1616-Since this crate is shared between multiple platforms, it should not pull in any platform specific dependencies. For example, if you want to use the `web_sys` crate in the web build of your app, you should not add it to this crate. Instead, you should add platform specific dependencies to the [web](../web/Cargo.toml), [desktop](../desktop/Cargo.toml), or [mobile](../mobile/Cargo.toml) crates.
···11-use dioxus::prelude::*;
22-33-const ECHO_CSS: Asset = asset!("/assets/styling/echo.css");
44-55-/// Echo component that demonstrates fullstack server functions.
66-#[component]
77-pub fn Echo() -> Element {
88- let mut response = use_signal(|| String::new());
99-1010- rsx! {
1111- document::Link { rel: "stylesheet", href: ECHO_CSS }
1212- div {
1313- id: "echo",
1414- h4 { "ServerFn Echo" }
1515- input {
1616- placeholder: "Type here to echo...",
1717- oninput: move |event| async move {
1818- let data = api::echo(event.value()).await.unwrap();
1919- response.set(data);
2020- },
2121- }
2222-2323- if !response().is_empty() {
2424- p {
2525- "Server echoed: "
2626- i { "{response}" }
2727- }
2828- }
2929- }
3030- }
3131-}
-24
packages/ui/src/hero.rs
···11-use dioxus::prelude::*;
22-33-const HERO_CSS: Asset = asset!("/assets/styling/hero.css");
44-const HEADER_SVG: Asset = asset!("/assets/header.svg");
55-66-#[component]
77-pub fn Hero() -> Element {
88- rsx! {
99- document::Link { rel: "stylesheet", href: HERO_CSS }
1010-1111- div {
1212- id: "hero",
1313- img { src: HEADER_SVG, id: "header" }
1414- div { id: "links",
1515- a { href: "https://dioxuslabs.com/learn/0.7/", "📚 Learn Dioxus" }
1616- a { href: "https://dioxuslabs.com/awesome", "🚀 Awesome Dioxus" }
1717- a { href: "https://github.com/dioxus-community/", "📡 Community Libraries" }
1818- a { href: "https://github.com/DioxusLabs/sdk", "⚙️ Dioxus Development Kit" }
1919- a { href: "https://marketplace.visualstudio.com/items?itemName=DioxusLabs.dioxus", "💫 VSCode Extension" }
2020- a { href: "https://discord.gg/XgGxMSkvUM", "👋 Community Discord" }
2121- }
2222- }
2323- }
2424-}
-10
packages/ui/src/lib.rs
···11-//! This crate contains all shared UI for the workspace.
22-33-mod hero;
44-pub use hero::Hero;
55-66-mod navbar;
77-pub use navbar::Navbar;
88-99-mod echo;
1010-pub use echo::Echo;
···11-# Development
22-33-The web crate defines the entrypoint for the web app along with any assets, components and dependencies that are specific to web builds. The web crate starts out something like this:
44-55-```
66-web/
77-├─ assets/ # Assets used by the web app - Any platform specific assets should go in this folder
88-├─ src/
99-│ ├─ main.rs # The entrypoint for the web app.It also defines the routes for the web platform
1010-│ ├─ views/ # The views each route will render in the web version of the app
1111-│ │ ├─ mod.rs # Defines the module for the views route and re-exports the components for each route
1212-│ │ ├─ blog.rs # The component that will render at the /blog/:id route
1313-│ │ ├─ home.rs # The component that will render at the / route
1414-├─ Cargo.toml # The web crate's Cargo.toml - This should include all web specific dependencies
1515-```
1616-1717-## Dependencies
1818-Since you have fullstack enabled, the web crate will be built two times:
1919-1. Once for the server build with the `server` feature enabled
2020-2. Once for the client build with the `web` feature enabled
2121-2222-You should make all web specific dependencies optional and only enabled in the `web` feature. This will ensure that the server builds don't pull in web specific dependencies which cuts down on build times significantly.
2323-2424-### Serving Your Web App
2525-2626-You can start your web app with the following command:
2727-2828-```bash
2929-dx serve
3030-```
···11-use dioxus::prelude::*;
22-33-use ui::Navbar;
44-use views::{Blog, Home};
55-66-mod views;
77-88-#[derive(Debug, Clone, Routable, PartialEq)]
99-#[rustfmt::skip]
1010-enum Route {
1111- #[layout(WebNavbar)]
1212- #[route("/")]
1313- Home {},
1414- #[route("/blog/:id")]
1515- Blog { id: i32 },
1616-}
1717-1818-const FAVICON: Asset = asset!("/assets/favicon.ico");
1919-const MAIN_CSS: Asset = asset!("/assets/main.css");
2020-2121-fn main() {
2222- dioxus::launch(App);
2323-}
2424-2525-#[component]
2626-fn App() -> Element {
2727- // Build cool things ✌️
2828-2929- rsx! {
3030- // Global app resources
3131- document::Link { rel: "icon", href: FAVICON }
3232- document::Link { rel: "stylesheet", href: MAIN_CSS }
3333-3434- Router::<Route> {}
3535- }
3636-}
3737-3838-/// A web-specific Router around the shared `Navbar` component
3939-/// which allows us to use the web-specific `Route` enum.
4040-#[component]
4141-fn WebNavbar() -> Element {
4242- rsx! {
4343- Navbar {
4444- Link {
4545- to: Route::Home {},
4646- "Home"
4747- }
4848- Link {
4949- to: Route::Blog { id: 1 },
5050- "Blog"
5151- }
5252- }
5353-5454- Outlet::<Route> {}
5555- }
5656-}
-30
packages/web/src/views/blog.rs
···11-use crate::Route;
22-use dioxus::prelude::*;
33-44-const BLOG_CSS: Asset = asset!("/assets/blog.css");
55-66-#[component]
77-pub fn Blog(id: i32) -> Element {
88- rsx! {
99- document::Link { rel: "stylesheet", href: BLOG_CSS}
1010-1111- div {
1212- id: "blog",
1313-1414- // Content
1515- h1 { "This is blog #{id}!" }
1616- p { "In blog #{id}, we show how the Dioxus router works and how URL parameters can be passed as props to our route components." }
1717-1818- // Navigation links
1919- Link {
2020- to: Route::Blog { id: id - 1 },
2121- "Previous"
2222- }
2323- span { " <---> " }
2424- Link {
2525- to: Route::Blog { id: id + 1 },
2626- "Next"
2727- }
2828- }
2929- }
3030-}