summary refs log tree commit diff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/app.rs51
-rw-r--r--src/components/editor/mod.rs13
-rw-r--r--src/components/renderer/mod.rs27
3 files changed, 84 insertions, 7 deletions
diff --git a/src/components/app.rs b/src/components/app.rs
index d93a870..5033359 100644
--- a/src/components/app.rs
+++ b/src/components/app.rs
@@ -1,10 +1,16 @@
 use leptos::prelude::*;
+use leptos::Params;
+use leptos_router::hooks::use_params;
+use leptos_router::hooks::use_query;
+use leptos_router::params::Params;
 use leptos_meta::{provide_meta_context, MetaTags, Stylesheet, Title};
 use leptos_router::{
-    components::{ParentRoute, Route, Router, Routes}, path, StaticSegment
+    components::{ParentRoute, Route, Router, Routes}, path
 };
 
 use crate::components::layout::Layout;
+use super::renderer::WikiPage;
+use super::editor::WikiEditor;
 
 pub fn shell(options: LeptosOptions) -> impl IntoView {
     view! {
@@ -32,7 +38,7 @@ pub fn App() -> impl IntoView {
     view! {
         // injects a stylesheet into the document <head>
         // id=leptos means cargo-leptos will hot-reload this stylesheet
-        <Stylesheet id="leptos" href="/pkg/stormscribe.css"/>
+        <Stylesheet id="leptos" href="/_/stormscribe.css"/>
 
         // sets the document title
         <Title text="Welcome to Leptos"/>
@@ -41,18 +47,49 @@ pub fn App() -> impl IntoView {
         <Router>
             <Routes fallback=|| "Page not found.".into_view()>
                 <ParentRoute path=path!("/") view=Layout>
-                    <Route path=path!("/") view=HomePage/>
+                    <Route path=path!("/~/*path") view=PageRender/>
+                    <Route path=path!("/edit/*path") view=PageEdit/>
                 </ParentRoute>
             </Routes>
         </Router>
     }
 }
 
-/// Renders the home page of your application.
+#[derive(Params, PartialEq)]
+struct PageParams {
+    path: Option<String>
+}
+
+// Renders a page
+#[component]
+fn PageRender() -> impl IntoView {
+    let params = use_params::<PageParams>();
+
+    let page_path = params.read()
+        .as_ref()
+        .ok()
+        .map(|params| params.path.clone()
+             .unwrap_or("Unknown path".to_string()))
+        .unwrap_or("Could not read params".to_string());
+
+    view! {
+        <WikiPage url_path=page_path />
+    }.into_any()
+}
+
+// Renders a page
 #[component]
-fn HomePage() -> impl IntoView {
+fn PageEdit() -> impl IntoView {
+    let params = use_params::<PageParams>();
+
+    let page_path = params.read()
+        .as_ref()
+        .ok()
+        .map(|params| params.path.clone()
+             .unwrap_or("Unknown path".to_string()))
+        .unwrap_or("Could not read params".to_string());
+
     view! {
-        <h1>Article</h1>
-        <p>Article content here we guess?</p>
+        <WikiEditor url_path=page_path />
     }
 }
diff --git a/src/components/editor/mod.rs b/src/components/editor/mod.rs
index e69de29..05e45d3 100644
--- a/src/components/editor/mod.rs
+++ b/src/components/editor/mod.rs
@@ -0,0 +1,13 @@
+use leptos::prelude::*;
+use leptos::{island, view, IntoView};
+
+#[island]
+pub fn WikiEditor(
+    url_path: String,
+) -> impl IntoView {
+    view! {
+        <h1>Article (Editing)</h1>
+        <p>Page render</p>
+        <pre>{url_path}</pre>
+    }
+}
diff --git a/src/components/renderer/mod.rs b/src/components/renderer/mod.rs
index e69de29..6bc029a 100644
--- a/src/components/renderer/mod.rs
+++ b/src/components/renderer/mod.rs
@@ -0,0 +1,27 @@
+use leptos::prelude::*;
+use leptos::{component, view, IntoView};
+
+// use crate::data::content::ContentController;
+
+#[component]
+pub fn WikiPage(
+    url_path: String,
+) -> impl IntoView {
+    // let content_controller = use_context::<ContentController>().unwrap();
+
+    // let _snapshot = Resource::new(
+    //     move || (url_path.clone(), content_controller.clone()),
+    //     |url_path: String| {
+    //         let page_path = url_path.clone();
+    //
+    //         async move {
+    //             let content = content_controller.get_snapshot().await;
+    //             let page = content.page_paths.get(&page_path);
+    //         }
+    //     });
+
+    view! {
+        <h1>Article (Viewing)</h1>
+        <p>Page render</p>
+    }
+}