-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a334cf
commit ac79996
Showing
6 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// This page illustrates SSR | ||
|
||
use serde::{Serialize, Deserialize}; | ||
use sycamore::prelude::{template, component, GenericNode, Template as SycamoreTemplate}; | ||
use perseus::template::Template; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct IpPageProps { | ||
ip: String, | ||
} | ||
|
||
#[component(IpPage<G>)] | ||
pub fn dashboard_page(props: IpPageProps) -> SycamoreTemplate<G> { | ||
template! { | ||
p { | ||
( | ||
format!("Your IP address is {}.", props.ip) | ||
) | ||
} | ||
} | ||
} | ||
|
||
pub fn get_page<G: GenericNode>() -> Template<G> { | ||
Template::new("ip") | ||
.request_state_fn(Box::new(get_request_state)) | ||
.template(template_fn()) | ||
} | ||
|
||
pub fn get_request_state(_path: String) -> String { | ||
serde_json::to_string( | ||
&IpPageProps { | ||
ip: "x.x.x.x".to_string() | ||
} | ||
).unwrap() | ||
} | ||
|
||
pub fn template_fn<G: GenericNode>() -> perseus::template::TemplateFn<G> { | ||
Box::new(|props: Option<String>| template! { | ||
IpPage( | ||
serde_json::from_str::<IpPageProps>(&props.unwrap()).unwrap() | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters