-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rs
86 lines (71 loc) · 2.34 KB
/
app.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use common::note::Note;
use common::space::OwnedSpace;
use common::Config;
use leptos::*;
use leptos_hotkeys::{provide_hotkeys_context, scopes, HotkeysContext};
use crate::backend::{load_config, load_theme};
use crate::notes::Notes;
use crate::spaces::Spaces;
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub enum FindNoteMode {
#[default]
None,
FindNote {
space: Option<OwnedSpace>,
},
}
impl FindNoteMode {
pub fn is_find_mode(&self) -> bool {
matches!(self, FindNoteMode::FindNote { .. })
}
}
#[derive(Debug, Clone)]
pub struct GlobalState {
pub spaces: Vec<OwnedSpace>,
pub notes: Vec<Note<'static>>,
pub selected_space: Option<OwnedSpace>,
pub minimize_spaces: bool,
pub find_note_mode: FindNoteMode,
}
impl Default for GlobalState {
fn default() -> Self {
Self {
spaces: Default::default(),
notes: Default::default(),
selected_space: Default::default(),
minimize_spaces: true,
find_note_mode: Default::default(),
}
}
}
#[component]
pub fn App() -> impl IntoView {
provide_context(create_rw_signal(GlobalState::default()));
provide_context(create_rw_signal(Config::default()));
let (theme_css, set_theme_css) = create_signal(String::default());
let (config, set_config) = create_signal(Config::default());
let main_ref = create_node_ref::<html::Main>();
let HotkeysContext { .. } = provide_hotkeys_context(main_ref, false, scopes!());
let global_config = expect_context::<RwSignal<Config>>();
spawn_local(async move {
let config = load_config().await;
info!("config: {:?}", config);
let theme = config.appearance.theme.clone();
global_config.set(config.clone());
set_config.set(config);
let theme = load_theme(&theme).await;
set_theme_css.set(theme.to_css());
});
let global_state = expect_context::<RwSignal<GlobalState>>();
let (spaces, set_spaces) = create_slice(
global_state,
|state| state.spaces.clone(),
|state, spaces| state.spaces = spaces,
);
view! {
<main class="app" style=move || theme_css.get() _ref=main_ref>
{move || view! { <Spaces config=config.get() spaces set_spaces /> }}
{move || view! { <Notes config=config.get() /> }}
</main>
}
}