Initial commit.
This commit is contained in:
commit
1bc79510f2
37 changed files with 6757 additions and 0 deletions
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
6101
Cargo.lock
generated
Normal file
6101
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
28
Cargo.toml
Normal file
28
Cargo.toml
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
[workspace]
|
||||||
|
resolver = "2"
|
||||||
|
members = [
|
||||||
|
"ui",
|
||||||
|
"web",
|
||||||
|
"desktop",
|
||||||
|
"mobile",
|
||||||
|
"server",
|
||||||
|
]
|
||||||
|
|
||||||
|
[workspace.dependencies]
|
||||||
|
dioxus = { version = "0.6.0" }
|
||||||
|
|
||||||
|
# workspace
|
||||||
|
ui = { path = "ui" }
|
||||||
|
server = { path = "server" }
|
||||||
|
|
||||||
|
[profile]
|
||||||
|
|
||||||
|
[profile.wasm-dev]
|
||||||
|
inherits = "dev"
|
||||||
|
opt-level = 1
|
||||||
|
|
||||||
|
[profile.server-dev]
|
||||||
|
inherits = "dev"
|
||||||
|
|
||||||
|
[profile.android-dev]
|
||||||
|
inherits = "dev"
|
19
README.md
Normal file
19
README.md
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Development
|
||||||
|
|
||||||
|
Depending on your selected options, your new workspace project contains a workspace member for each platform.
|
||||||
|
If you chose to develop with the router feature, each platform crate will have a `views` folder for your platform-specific views.
|
||||||
|
You are provided with a `ui` crate for shared UI and if you chose to use fullstack, you will have a `server` crate for your shared server functions.
|
||||||
|
|
||||||
|
### Serving Your App
|
||||||
|
|
||||||
|
Navigate to the platform crate of your choice:
|
||||||
|
```bash
|
||||||
|
cd web
|
||||||
|
```
|
||||||
|
|
||||||
|
and serve:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dx serve
|
||||||
|
```
|
||||||
|
|
13
desktop/Cargo.toml
Normal file
13
desktop/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "desktop"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
dioxus = { workspace = true, features = ["router"] }
|
||||||
|
ui = { workspace = true }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
desktop = ["dioxus/desktop"]
|
||||||
|
server = ["dioxus/server"]
|
8
desktop/assets/blog.css
Normal file
8
desktop/assets/blog.css
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#blog {
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#blog a {
|
||||||
|
color: #ffffff;
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
6
desktop/assets/main.css
Normal file
6
desktop/assets/main.css
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
body {
|
||||||
|
background-color: #0f1116;
|
||||||
|
color: #ffffff;
|
||||||
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||||
|
margin: 20px;
|
||||||
|
}
|
54
desktop/src/main.rs
Normal file
54
desktop/src/main.rs
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
use ui::Navbar;
|
||||||
|
use views::{Blog, Home};
|
||||||
|
|
||||||
|
mod views;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Routable, PartialEq)]
|
||||||
|
#[rustfmt::skip]
|
||||||
|
enum Route {
|
||||||
|
#[layout(DesktopNavbar)]
|
||||||
|
#[route("/")]
|
||||||
|
Home {},
|
||||||
|
#[route("/blog/:id")]
|
||||||
|
Blog { id: i32 },
|
||||||
|
}
|
||||||
|
|
||||||
|
const MAIN_CSS: Asset = asset!("/assets/main.css");
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
dioxus::launch(App);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
fn App() -> Element {
|
||||||
|
// Build cool things ✌️
|
||||||
|
|
||||||
|
rsx! {
|
||||||
|
// Global app resources
|
||||||
|
document::Link { rel: "stylesheet", href: MAIN_CSS }
|
||||||
|
|
||||||
|
Router::<Route> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A desktop-specific Router around the shared `Navbar` component
|
||||||
|
/// which allows us to use the desktop-specific `Route` enum.
|
||||||
|
#[component]
|
||||||
|
fn DesktopNavbar() -> Element {
|
||||||
|
rsx! {
|
||||||
|
Navbar {
|
||||||
|
Link {
|
||||||
|
to: Route::Home {},
|
||||||
|
"Home"
|
||||||
|
}
|
||||||
|
Link {
|
||||||
|
to: Route::Blog { id: 1 },
|
||||||
|
"Blog"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Outlet::<Route> {}
|
||||||
|
}
|
||||||
|
}
|
30
desktop/src/views/blog.rs
Normal file
30
desktop/src/views/blog.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
use crate::Route;
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
const BLOG_CSS: Asset = asset!("/assets/blog.css");
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Blog(id: i32) -> Element {
|
||||||
|
rsx! {
|
||||||
|
document::Link { rel: "stylesheet", href: BLOG_CSS}
|
||||||
|
|
||||||
|
div {
|
||||||
|
id: "blog",
|
||||||
|
|
||||||
|
// Content
|
||||||
|
h1 { "This is blog #{id}!" }
|
||||||
|
p { "In blog #{id}, we show how the Dioxus router works and how URL parameters can be passed as props to our route components." }
|
||||||
|
|
||||||
|
// Navigation links
|
||||||
|
Link {
|
||||||
|
to: Route::Blog { id: id - 1 },
|
||||||
|
"Previous"
|
||||||
|
}
|
||||||
|
span { " <---> " }
|
||||||
|
Link {
|
||||||
|
to: Route::Blog { id: id + 1 },
|
||||||
|
"Next"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
desktop/src/views/home.rs
Normal file
10
desktop/src/views/home.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
use ui::{Echo, Hero};
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Home() -> Element {
|
||||||
|
rsx! {
|
||||||
|
Hero {}
|
||||||
|
Echo {}
|
||||||
|
}
|
||||||
|
}
|
5
desktop/src/views/mod.rs
Normal file
5
desktop/src/views/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
mod home;
|
||||||
|
pub use home::Home;
|
||||||
|
|
||||||
|
mod blog;
|
||||||
|
pub use blog::Blog;
|
13
mobile/Cargo.toml
Normal file
13
mobile/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "mobile"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
dioxus = { workspace = true, features = ["router"] }
|
||||||
|
ui = { workspace = true }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
mobile = ["dioxus/mobile"]
|
||||||
|
server = ["dioxus/server"]
|
8
mobile/assets/blog.css
Normal file
8
mobile/assets/blog.css
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#blog {
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#blog a {
|
||||||
|
color: #ffffff;
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
6
mobile/assets/main.css
Normal file
6
mobile/assets/main.css
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
body {
|
||||||
|
background-color: #0f1116;
|
||||||
|
color: #ffffff;
|
||||||
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||||
|
margin: 20px;
|
||||||
|
}
|
54
mobile/src/main.rs
Normal file
54
mobile/src/main.rs
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
use ui::Navbar;
|
||||||
|
use views::{Blog, Home};
|
||||||
|
|
||||||
|
mod views;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Routable, PartialEq)]
|
||||||
|
#[rustfmt::skip]
|
||||||
|
enum Route {
|
||||||
|
#[layout(MobileNavbar)]
|
||||||
|
#[route("/")]
|
||||||
|
Home {},
|
||||||
|
#[route("/blog/:id")]
|
||||||
|
Blog { id: i32 },
|
||||||
|
}
|
||||||
|
|
||||||
|
const MAIN_CSS: Asset = asset!("/assets/main.css");
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
dioxus::launch(App);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
fn App() -> Element {
|
||||||
|
// Build cool things ✌️
|
||||||
|
|
||||||
|
rsx! {
|
||||||
|
// Global app resources
|
||||||
|
document::Link { rel: "stylesheet", href: MAIN_CSS }
|
||||||
|
|
||||||
|
Router::<Route> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A mobile-specific Router around the shared `Navbar` component
|
||||||
|
/// which allows us to use the mobile-specific `Route` enum.
|
||||||
|
#[component]
|
||||||
|
fn MobileNavbar() -> Element {
|
||||||
|
rsx! {
|
||||||
|
Navbar {
|
||||||
|
Link {
|
||||||
|
to: Route::Home {},
|
||||||
|
"Home"
|
||||||
|
}
|
||||||
|
Link {
|
||||||
|
to: Route::Blog { id: 1 },
|
||||||
|
"Blog"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Outlet::<Route> {}
|
||||||
|
}
|
||||||
|
}
|
30
mobile/src/views/blog.rs
Normal file
30
mobile/src/views/blog.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
use crate::Route;
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
const BLOG_CSS: Asset = asset!("/assets/blog.css");
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Blog(id: i32) -> Element {
|
||||||
|
rsx! {
|
||||||
|
document::Link { rel: "stylesheet", href: BLOG_CSS}
|
||||||
|
|
||||||
|
div {
|
||||||
|
id: "blog",
|
||||||
|
|
||||||
|
// Content
|
||||||
|
h1 { "This is blog #{id}!" }
|
||||||
|
p { "In blog #{id}, we show how the Dioxus router works and how URL parameters can be passed as props to our route components." }
|
||||||
|
|
||||||
|
// Navigation links
|
||||||
|
Link {
|
||||||
|
to: Route::Blog { id: id - 1 },
|
||||||
|
"Previous"
|
||||||
|
}
|
||||||
|
span { " <---> " }
|
||||||
|
Link {
|
||||||
|
to: Route::Blog { id: id + 1 },
|
||||||
|
"Next"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
mobile/src/views/home.rs
Normal file
10
mobile/src/views/home.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
use ui::{Echo, Hero};
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Home() -> Element {
|
||||||
|
rsx! {
|
||||||
|
Hero {}
|
||||||
|
Echo {}
|
||||||
|
}
|
||||||
|
}
|
5
mobile/src/views/mod.rs
Normal file
5
mobile/src/views/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
mod home;
|
||||||
|
pub use home::Home;
|
||||||
|
|
||||||
|
mod blog;
|
||||||
|
pub use blog::Blog;
|
7
server/Cargo.toml
Normal file
7
server/Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
[package]
|
||||||
|
name = "server"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
dioxus = { workspace = true, features = ["fullstack"] }
|
18
server/src/lib.rs
Normal file
18
server/src/lib.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
//! This crate contains all shared fullstack server functions.
|
||||||
|
use dioxus::{logger::tracing::debug, prelude::*};
|
||||||
|
|
||||||
|
/// Echo the user input on the server.
|
||||||
|
#[server(Echo)]
|
||||||
|
pub async fn echo(input: String) -> Result<String, ServerFnError> {
|
||||||
|
Ok(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[server]
|
||||||
|
pub async fn test_fn() -> Result<(), ServerFnError> {
|
||||||
|
debug!("Here");
|
||||||
|
#[cfg(feature = "server")]
|
||||||
|
{
|
||||||
|
debug!("This is only on the server.");
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
8
ui/Cargo.toml
Normal file
8
ui/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "ui"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
dioxus = { workspace = true }
|
||||||
|
server = { workspace = true }
|
20
ui/assets/header.svg
Normal file
20
ui/assets/header.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 23 KiB |
34
ui/assets/styling/echo.css
Normal file
34
ui/assets/styling/echo.css
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#echo {
|
||||||
|
width: 360px;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
margin-top: 50px;
|
||||||
|
background-color: #1e222d;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#echo>h4 {
|
||||||
|
margin: 0px 0px 15px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#echo>input {
|
||||||
|
border: none;
|
||||||
|
border-bottom: 1px white solid;
|
||||||
|
background-color: transparent;
|
||||||
|
color: #ffffff;
|
||||||
|
transition: border-bottom-color 0.2s ease;
|
||||||
|
outline: none;
|
||||||
|
display: block;
|
||||||
|
padding: 0px 0px 5px 0px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#echo>input:focus {
|
||||||
|
border-bottom-color: #6d85c6;
|
||||||
|
}
|
||||||
|
|
||||||
|
#echo>p {
|
||||||
|
margin: 20px 0px 0px auto;
|
||||||
|
}
|
35
ui/assets/styling/hero.css
Normal file
35
ui/assets/styling/hero.css
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#hero {
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#links {
|
||||||
|
width: 400px;
|
||||||
|
text-align: left;
|
||||||
|
font-size: x-large;
|
||||||
|
color: white;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
#links a {
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
margin-top: 20px;
|
||||||
|
margin: 10px 0px;
|
||||||
|
border: white 1px solid;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#links a:hover {
|
||||||
|
background-color: #1f1f1f;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#header {
|
||||||
|
max-width: 1200px;
|
||||||
|
}
|
16
ui/assets/styling/navbar.css
Normal file
16
ui/assets/styling/navbar.css
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#navbar {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navbar a {
|
||||||
|
color: #ffffff;
|
||||||
|
margin-right: 20px;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: color 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navbar a:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
color: #91a4d2;
|
||||||
|
}
|
31
ui/src/echo.rs
Normal file
31
ui/src/echo.rs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
const ECHO_CSS: Asset = asset!("/assets/styling/echo.css");
|
||||||
|
|
||||||
|
/// Echo component that demonstrates fullstack server functions.
|
||||||
|
#[component]
|
||||||
|
pub fn Echo() -> Element {
|
||||||
|
let mut response = use_signal(|| String::new());
|
||||||
|
|
||||||
|
rsx! {
|
||||||
|
document::Link { rel: "stylesheet", href: ECHO_CSS }
|
||||||
|
div {
|
||||||
|
id: "echo",
|
||||||
|
h4 { "ServerFn Echo" }
|
||||||
|
input {
|
||||||
|
placeholder: "Type here to echo...",
|
||||||
|
oninput: move |event| async move {
|
||||||
|
let data = server::echo(event.value()).await.unwrap();
|
||||||
|
response.set(data);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if !response().is_empty() {
|
||||||
|
p {
|
||||||
|
"Server echoed: "
|
||||||
|
i { "{response}" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
ui/src/hero.rs
Normal file
28
ui/src/hero.rs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
const HERO_CSS: Asset = asset!("/assets/styling/hero.css");
|
||||||
|
const HEADER_SVG: Asset = asset!("/assets/header.svg");
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Hero() -> Element {
|
||||||
|
spawn(async move {
|
||||||
|
server::test_fn().await.unwrap();
|
||||||
|
});
|
||||||
|
rsx! {
|
||||||
|
document::Link { rel: "stylesheet", href: HERO_CSS }
|
||||||
|
|
||||||
|
div { id: "hero",
|
||||||
|
img { src: HEADER_SVG, id: "header" }
|
||||||
|
div { id: "links",
|
||||||
|
a { href: "https://dioxuslabs.com/learn/0.6/", "📚 Learn Dioxus" }
|
||||||
|
a { href: "https://dioxuslabs.com/awesome", "🚀 Awesome Dioxus" }
|
||||||
|
a { href: "https://github.com/dioxus-community/", "📡 Community Libraries" }
|
||||||
|
a { href: "https://github.com/DioxusLabs/sdk", "⚙️ Dioxus Development Kit" }
|
||||||
|
a { href: "https://marketplace.visualstudio.com/items?itemName=DioxusLabs.dioxus",
|
||||||
|
"💫 VSCode Extension"
|
||||||
|
}
|
||||||
|
a { href: "https://discord.gg/XgGxMSkvUM", "👋 Community Discord" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
ui/src/lib.rs
Normal file
10
ui/src/lib.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
//! This crate contains all shared UI for the workspace.
|
||||||
|
|
||||||
|
mod hero;
|
||||||
|
pub use hero::Hero;
|
||||||
|
|
||||||
|
mod navbar;
|
||||||
|
pub use navbar::Navbar;
|
||||||
|
|
||||||
|
mod echo;
|
||||||
|
pub use echo::Echo;
|
15
ui/src/navbar.rs
Normal file
15
ui/src/navbar.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
const NAVBAR_CSS: Asset = asset!("/assets/styling/navbar.css");
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Navbar(children: Element) -> Element {
|
||||||
|
rsx! {
|
||||||
|
document::Link { rel: "stylesheet", href: NAVBAR_CSS }
|
||||||
|
|
||||||
|
div {
|
||||||
|
id: "navbar",
|
||||||
|
{children}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
web/Cargo.toml
Normal file
13
web/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "web"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
dioxus = { workspace = true, features = ["router"] }
|
||||||
|
ui = { workspace = true }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
web = ["dioxus/web"]
|
||||||
|
server = ["dioxus/server"]
|
8
web/assets/blog.css
Normal file
8
web/assets/blog.css
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#blog {
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#blog a {
|
||||||
|
color: #ffffff;
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
BIN
web/assets/favicon.ico
Normal file
BIN
web/assets/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 130 KiB |
6
web/assets/main.css
Normal file
6
web/assets/main.css
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
body {
|
||||||
|
background-color: #0f1116;
|
||||||
|
color: #ffffff;
|
||||||
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||||
|
margin: 20px;
|
||||||
|
}
|
56
web/src/main.rs
Normal file
56
web/src/main.rs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
use ui::Navbar;
|
||||||
|
use views::{Blog, Home};
|
||||||
|
|
||||||
|
mod views;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Routable, PartialEq)]
|
||||||
|
#[rustfmt::skip]
|
||||||
|
enum Route {
|
||||||
|
#[layout(WebNavbar)]
|
||||||
|
#[route("/")]
|
||||||
|
Home {},
|
||||||
|
#[route("/blog/:id")]
|
||||||
|
Blog { id: i32 },
|
||||||
|
}
|
||||||
|
|
||||||
|
const FAVICON: Asset = asset!("/assets/favicon.ico");
|
||||||
|
const MAIN_CSS: Asset = asset!("/assets/main.css");
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
dioxus::launch(App);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
fn App() -> Element {
|
||||||
|
// Build cool things ✌️
|
||||||
|
|
||||||
|
rsx! {
|
||||||
|
// Global app resources
|
||||||
|
document::Link { rel: "icon", href: FAVICON }
|
||||||
|
document::Link { rel: "stylesheet", href: MAIN_CSS }
|
||||||
|
|
||||||
|
Router::<Route> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A web-specific Router around the shared `Navbar` component
|
||||||
|
/// which allows us to use the web-specific `Route` enum.
|
||||||
|
#[component]
|
||||||
|
fn WebNavbar() -> Element {
|
||||||
|
rsx! {
|
||||||
|
Navbar {
|
||||||
|
Link {
|
||||||
|
to: Route::Home {},
|
||||||
|
"Home"
|
||||||
|
}
|
||||||
|
Link {
|
||||||
|
to: Route::Blog { id: 1 },
|
||||||
|
"Blog"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Outlet::<Route> {}
|
||||||
|
}
|
||||||
|
}
|
30
web/src/views/blog.rs
Normal file
30
web/src/views/blog.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
use crate::Route;
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
const BLOG_CSS: Asset = asset!("/assets/blog.css");
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Blog(id: i32) -> Element {
|
||||||
|
rsx! {
|
||||||
|
document::Link { rel: "stylesheet", href: BLOG_CSS}
|
||||||
|
|
||||||
|
div {
|
||||||
|
id: "blog",
|
||||||
|
|
||||||
|
// Content
|
||||||
|
h1 { "This is blog #{id}!" }
|
||||||
|
p { "In blog #{id}, we show how the Dioxus router works and how URL parameters can be passed as props to our route components." }
|
||||||
|
|
||||||
|
// Navigation links
|
||||||
|
Link {
|
||||||
|
to: Route::Blog { id: id - 1 },
|
||||||
|
"Previous"
|
||||||
|
}
|
||||||
|
span { " <---> " }
|
||||||
|
Link {
|
||||||
|
to: Route::Blog { id: id + 1 },
|
||||||
|
"Next"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
web/src/views/home.rs
Normal file
10
web/src/views/home.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
use ui::{Echo, Hero};
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Home() -> Element {
|
||||||
|
rsx! {
|
||||||
|
Hero {}
|
||||||
|
Echo {}
|
||||||
|
}
|
||||||
|
}
|
5
web/src/views/mod.rs
Normal file
5
web/src/views/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
mod home;
|
||||||
|
pub use home::Home;
|
||||||
|
|
||||||
|
mod blog;
|
||||||
|
pub use blog::Blog;
|
Loading…
Add table
Reference in a new issue