chore: import MCTF services
- Added all seven issued service trees without omissions. - Preserved the supplied runtime configuration, binaries, and assets.
This commit is contained in:
commit
13f936bee9
1222 files changed
+21280
No files matched your search
Executable
+202
@@ -0,0 +1,202 @@
|
||||
use dioxus::prelude::*;
|
||||
use uuid::Uuid;
|
||||
|
||||
use components::{AppLayout, UserBadge};
|
||||
use state::{Page, CURRENT_PAGE};
|
||||
use views::{
|
||||
ApiErrorToast, CreateWorkspacePage, FileCreatePage, Home, LoginPage, MyFiles,
|
||||
PasswordChangePage, PublicFiles, RegisterPage, WorkspaceOverview, WorkspaceSettings,
|
||||
};
|
||||
|
||||
mod api_client;
|
||||
mod auth;
|
||||
mod components;
|
||||
mod state;
|
||||
mod views;
|
||||
|
||||
#[derive(Debug, Clone, Routable, PartialEq)]
|
||||
#[rustfmt::skip]
|
||||
enum Route {
|
||||
#[route("/login")]
|
||||
LoginPage {},
|
||||
|
||||
#[route("/register")]
|
||||
RegisterPage {},
|
||||
|
||||
#[layout(WebLayout)]
|
||||
#[route("/")]
|
||||
Home {},
|
||||
|
||||
#[route("/workspace/create")]
|
||||
CreateWorkspacePage {},
|
||||
|
||||
#[route("/workspace")]
|
||||
WorkspaceOverview {},
|
||||
|
||||
#[route("/workspace/settings")]
|
||||
WorkspaceSettings {},
|
||||
|
||||
#[route("/files")]
|
||||
PublicFiles {},
|
||||
|
||||
#[route("/files/create")]
|
||||
FileCreatePage {},
|
||||
|
||||
#[route("/workspace/:workspace_id/files/create")]
|
||||
WorkspaceFileCreatePage { workspace_id: Uuid },
|
||||
|
||||
#[route("/my-files")]
|
||||
MyFiles {},
|
||||
|
||||
#[route("/change-password")]
|
||||
PasswordChangePage {}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn WorkspaceFileCreatePage(workspace_id: Uuid) -> Element {
|
||||
rsx! { FileCreatePage { workspace_id: Some(workspace_id) } }
|
||||
}
|
||||
|
||||
const FAVICON: Asset = asset!("/assets/favicon.ico");
|
||||
const MAIN_CSS: Asset = asset!("/assets/main.css");
|
||||
const TAILWIND_CSS: Asset = asset!("/assets/tailwind.css");
|
||||
|
||||
fn main() {
|
||||
#[cfg(feature = "server")]
|
||||
dioxus::serve(|| async move {
|
||||
let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
||||
let pool = api::db::establish_connection(&db_url)
|
||||
.await
|
||||
.expect("failed to connect to database");
|
||||
|
||||
let router = dioxus::server::router(App).nest("/api", api::router(pool));
|
||||
|
||||
Ok(router)
|
||||
});
|
||||
|
||||
#[cfg(not(feature = "server"))]
|
||||
dioxus::launch(App);
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn App() -> Element {
|
||||
let auth::Auth(mut current_user) =
|
||||
use_context_provider(|| auth::Auth(Signal::new(auth::AuthState::Checking)));
|
||||
|
||||
use_effect(move || {
|
||||
if !matches!(*current_user.read(), auth::AuthState::Checking) {
|
||||
return;
|
||||
}
|
||||
|
||||
spawn(async move {
|
||||
let Some(saved) = auth::restore() else {
|
||||
current_user.set(auth::AuthState::Guest);
|
||||
return;
|
||||
};
|
||||
|
||||
match crate::api_client::ApiClient::me(&saved.token).await {
|
||||
Ok(_) => current_user.set(auth::AuthState::User(saved)),
|
||||
Err(crate::api_client::ApiClientError::Status(401, _)) => {
|
||||
auth::clear_persisted();
|
||||
current_user.set(auth::AuthState::Guest);
|
||||
}
|
||||
Err(_) => current_user.set(auth::AuthState::Guest),
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
rsx! {
|
||||
document::Title { "pamsave" }
|
||||
document::Link {
|
||||
rel: "preconnect",
|
||||
href: "https://fonts.googleapis.com"
|
||||
}
|
||||
document::Link {
|
||||
rel: "preconnect",
|
||||
href: "https://fonts.gstatic.com",
|
||||
crossorigin: "anonymous"
|
||||
}
|
||||
document::Link {
|
||||
rel: "stylesheet",
|
||||
href: "https://fonts.googleapis.com/css2?family=Pixelify+Sans:wght@400..700&display=swap"
|
||||
}
|
||||
|
||||
|
||||
document::Link { rel: "icon", href: FAVICON }
|
||||
document::Link { rel: "stylesheet", href: MAIN_CSS }
|
||||
document::Stylesheet { href: TAILWIND_CSS }
|
||||
|
||||
Router::<Route> {}
|
||||
ApiErrorToast {}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn WebLayout() -> Element {
|
||||
let nav = use_navigator();
|
||||
let auth::Auth(mut current_user) = use_context::<auth::Auth>();
|
||||
|
||||
let title = match CURRENT_PAGE() {
|
||||
Page::MyFiles => "My Files",
|
||||
Page::PublicFiles => "Public Files",
|
||||
Page::MyWorkspace {} => "My Workspace",
|
||||
Page::CreateWorkspace {} => "New Workspace",
|
||||
Page::CreateFile {} => "Create File",
|
||||
};
|
||||
|
||||
let header = rsx! {
|
||||
div {}
|
||||
div {
|
||||
class: "flex flex-1 justify-center",
|
||||
span {
|
||||
class: "flex justify-center items-center text-cyan-300 text-3xl px-6 h-16 border-r border-l border-slate-800 min-w-65",
|
||||
"{title}"
|
||||
}
|
||||
}
|
||||
div {
|
||||
class: "flex items-center gap-2 justify-end",
|
||||
if let Some(user) = current_user.read().user_cloned() {
|
||||
div {
|
||||
class: "relative group flex items-center",
|
||||
UserBadge { username: user.username }
|
||||
div {
|
||||
class: "absolute right-0 top-full pt-1 hidden group-hover:block z-50",
|
||||
div {
|
||||
class: "border border-slate-800 rounded-[0.5rem] overflow-hidden bg-slate-950",
|
||||
Link {
|
||||
class: "block px-4 py-2 whitespace-nowrap text-slate-100 transition-colors hover:bg-cyan-300 hover:text-black",
|
||||
to: Route::PasswordChangePage {},
|
||||
"Change Password"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
button {
|
||||
class: "border border-cyan-300 rounded-[1rem] p-1.5 transition-colors hover:text-black hover:bg-cyan-300",
|
||||
onclick: move |_| {
|
||||
let token = user.token.clone();
|
||||
spawn(async move {
|
||||
let _ = crate::api_client::ApiClient::logout(&token).await;
|
||||
});
|
||||
auth::clear_persisted();
|
||||
current_user.set(auth::AuthState::Guest);
|
||||
nav.push(Route::LoginPage {});
|
||||
},
|
||||
"Sign Out"
|
||||
}
|
||||
} else if current_user.read().is_guest() {
|
||||
button {
|
||||
class: "border border-cyan-300 rounded-[1rem] p-1.5 transition-colors hover:text-black hover:bg-cyan-300",
|
||||
onclick: move |_| { nav.push(Route::LoginPage {}); },
|
||||
"Sign In"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
rsx! {
|
||||
AppLayout {
|
||||
header,
|
||||
Outlet::<Route> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user