56
src/features/command_line/mod.rs
Normal file
56
src/features/command_line/mod.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use leptos::*;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CommandLineState {
|
||||
hidden: bool,
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn CommandLineModalView(cx: Scope) -> impl IntoView {
|
||||
view! { cx, <div>"modal"</div> }
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn CommandLineModal(cx: Scope) -> impl IntoView {
|
||||
let state =
|
||||
use_context::<RwSignal<CommandLineState>>(cx).expect("command line state must be provided");
|
||||
|
||||
let (hidden, _) = create_slice(cx, state, |state| state.hidden, |state, n| state.hidden = n);
|
||||
|
||||
view! { cx,
|
||||
{move || {
|
||||
if !hidden.get() {
|
||||
view! { cx, <CommandLineModalView/> }
|
||||
} else {
|
||||
view! { cx, }
|
||||
}
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn CommandLine(cx: Scope, children: Children) -> impl IntoView {
|
||||
let state = create_rw_signal(cx, CommandLineState { hidden: true });
|
||||
provide_context(cx, state);
|
||||
let (hidden, set_hidden) =
|
||||
create_slice(cx, state, |state| state.hidden, |state, n| state.hidden = n);
|
||||
|
||||
leptos_dom::helpers::window_event_listener(ev::keypress, move |event| {
|
||||
if event.ctrl_key() {
|
||||
match event.code().as_str() {
|
||||
"KeyK" => {
|
||||
set_hidden(!hidden.get());
|
||||
log!("toggle command")
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
view! { cx,
|
||||
<div>
|
||||
<div>{children(cx)}</div>
|
||||
<CommandLineModal/>
|
||||
</div>
|
||||
}
|
||||
}
|
4
src/features/dashboard_list_view.rs
Normal file
4
src/features/dashboard_list_view.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub mod dashboard_list_view;
|
||||
pub mod gen;
|
||||
|
||||
pub use dashboard_list_view::*;
|
93
src/features/dashboard_list_view/dashboard_list_view.rs
Normal file
93
src/features/dashboard_list_view/dashboard_list_view.rs
Normal file
@@ -0,0 +1,93 @@
|
||||
use graphql_client::{GraphQLQuery, Response};
|
||||
use leptos::*;
|
||||
|
||||
use crate::features::dashboard_list_view::gen::queries::get_projects_list_view::GetProjectsListViewGetProjectsItems;
|
||||
|
||||
use super::gen::queries::get_projects_list_view::{
|
||||
GetProjectsListViewGetProjects, ResponseData, Variables,
|
||||
};
|
||||
use super::gen::queries::GetProjectsListView;
|
||||
|
||||
pub async fn get_projects_list() -> anyhow::Result<Vec<GetProjectsListViewGetProjects>> {
|
||||
let request_body = GetProjectsListView::build_query(Variables {});
|
||||
let payload = serde_json::to_string(&request_body)?;
|
||||
let res = reqwasm::http::Request::post("http://localhost:3001/graphql")
|
||||
.credentials(reqwasm::http::RequestCredentials::Include)
|
||||
.body(payload)
|
||||
.send()
|
||||
.await?;
|
||||
let response_body: Response<ResponseData> = res.json().await?;
|
||||
Ok(response_body
|
||||
.data
|
||||
.ok_or(anyhow::anyhow!("failed to get projects list"))?
|
||||
.get_projects)
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn DashboardItemView(cx: Scope, item: GetProjectsListViewGetProjectsItems) -> impl IntoView {
|
||||
view! { cx, <div class="dashboard-list-item dashboard-item">{item.title}</div> }
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn DashboardProjectItemView(
|
||||
cx: Scope,
|
||||
project: GetProjectsListViewGetProjects,
|
||||
) -> impl IntoView {
|
||||
view! { cx,
|
||||
<div class="dashboard-list-item dashboard-list-project">
|
||||
<a href=format!("/dash/project/{}", & project.id) class="project-item flex flex-row">
|
||||
<div class="space-x-2">
|
||||
<span>{&project.name}</span>
|
||||
<span class="text-gray-50">{project.items.len()}</span>
|
||||
<span class="flex-grow"></span>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn DashboardListView(
|
||||
cx: Scope,
|
||||
projects: Resource<(), Vec<GetProjectsListViewGetProjects>>,
|
||||
) -> impl IntoView {
|
||||
let projects_view = move || {
|
||||
projects.with(cx, |projects| {
|
||||
if projects.is_empty() {
|
||||
return vec![view! { cx, <div class="project-item">"No projects"</div> }.into_any()];
|
||||
}
|
||||
|
||||
projects
|
||||
.into_iter()
|
||||
.filter(|project| !project.items.is_empty())
|
||||
.map(|project| {
|
||||
view! { cx,
|
||||
<div>
|
||||
<DashboardProjectItemView project=project.clone()/>
|
||||
{&project
|
||||
.items
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|item| {
|
||||
view! { cx, <DashboardItemView item=item/> }
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.into_view(cx)}
|
||||
</div>
|
||||
}
|
||||
.into_any()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
};
|
||||
|
||||
view! { cx, <div class="project-items">{projects_view}</div> }
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn DashboardList(cx: Scope) -> impl IntoView {
|
||||
let projects =
|
||||
create_local_resource(cx, || (), |_| async { get_projects_list().await.unwrap() });
|
||||
|
||||
view! { cx, <DashboardListView projects=projects/> }
|
||||
}
|
1
src/features/dashboard_list_view/gen/mod.rs
Normal file
1
src/features/dashboard_list_view/gen/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod queries;
|
81
src/features/dashboard_list_view/gen/queries.rs
Normal file
81
src/features/dashboard_list_view/gen/queries.rs
Normal file
@@ -0,0 +1,81 @@
|
||||
#![allow(clippy::all, warnings)]
|
||||
pub struct GetProjectsListView;
|
||||
pub mod get_projects_list_view {
|
||||
#![allow(dead_code)]
|
||||
use std::result::Result;
|
||||
pub const OPERATION_NAME: &str = "GetProjectsListView";
|
||||
pub const QUERY : & str = "query GetProjectsListView {\n getProjects {\n id\n name\n\n items {\n id\n title\n description\n state\n }\n }\n}\n" ;
|
||||
use super::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(dead_code)]
|
||||
type Boolean = bool;
|
||||
#[allow(dead_code)]
|
||||
type Float = f64;
|
||||
#[allow(dead_code)]
|
||||
type Int = i64;
|
||||
#[allow(dead_code)]
|
||||
type ID = String;
|
||||
type UUID = crate::common::graphql::UUID;
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ItemState {
|
||||
CREATED,
|
||||
DONE,
|
||||
ARCHIVED,
|
||||
DELETED,
|
||||
Other(String),
|
||||
}
|
||||
impl ::serde::Serialize for ItemState {
|
||||
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
|
||||
ser.serialize_str(match *self {
|
||||
ItemState::CREATED => "CREATED",
|
||||
ItemState::DONE => "DONE",
|
||||
ItemState::ARCHIVED => "ARCHIVED",
|
||||
ItemState::DELETED => "DELETED",
|
||||
ItemState::Other(ref s) => &s,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl<'de> ::serde::Deserialize<'de> for ItemState {
|
||||
fn deserialize<D: ::serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||
let s: String = ::serde::Deserialize::deserialize(deserializer)?;
|
||||
match s.as_str() {
|
||||
"CREATED" => Ok(ItemState::CREATED),
|
||||
"DONE" => Ok(ItemState::DONE),
|
||||
"ARCHIVED" => Ok(ItemState::ARCHIVED),
|
||||
"DELETED" => Ok(ItemState::DELETED),
|
||||
_ => Ok(ItemState::Other(s)),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Serialize, Clone, Debug)]
|
||||
pub struct Variables;
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
pub struct ResponseData {
|
||||
#[serde(rename = "getProjects")]
|
||||
pub get_projects: Vec<GetProjectsListViewGetProjects>,
|
||||
}
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
pub struct GetProjectsListViewGetProjects {
|
||||
pub id: UUID,
|
||||
pub name: String,
|
||||
pub items: Vec<GetProjectsListViewGetProjectsItems>,
|
||||
}
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
pub struct GetProjectsListViewGetProjectsItems {
|
||||
pub id: UUID,
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub state: ItemState,
|
||||
}
|
||||
}
|
||||
impl graphql_client::GraphQLQuery for GetProjectsListView {
|
||||
type Variables = get_projects_list_view::Variables;
|
||||
type ResponseData = get_projects_list_view::ResponseData;
|
||||
fn build_query(variables: Self::Variables) -> ::graphql_client::QueryBody<Self::Variables> {
|
||||
graphql_client::QueryBody {
|
||||
variables,
|
||||
query: get_projects_list_view::QUERY,
|
||||
operation_name: get_projects_list_view::OPERATION_NAME,
|
||||
}
|
||||
}
|
||||
}
|
13
src/features/dashboard_list_view/graphql/queries.graphql
Normal file
13
src/features/dashboard_list_view/graphql/queries.graphql
Normal file
@@ -0,0 +1,13 @@
|
||||
query GetProjectsListView {
|
||||
getProjects {
|
||||
id
|
||||
name
|
||||
|
||||
items {
|
||||
id
|
||||
title
|
||||
description
|
||||
state
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,14 +17,14 @@ pub mod get_projects_list_view {
|
||||
#[allow(dead_code)]
|
||||
type ID = String;
|
||||
type UUID = crate::common::graphql::UUID;
|
||||
#[derive(Serialize)]
|
||||
#[derive(Serialize, Clone, Debug)]
|
||||
pub struct Variables;
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
pub struct ResponseData {
|
||||
#[serde(rename = "getProjects")]
|
||||
pub get_projects: Vec<GetProjectsListViewGetProjects>,
|
||||
}
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
pub struct GetProjectsListViewGetProjects {
|
||||
pub id: UUID,
|
||||
pub name: String,
|
||||
|
@@ -1,6 +1,5 @@
|
||||
use graphql_client::{GraphQLQuery, Response};
|
||||
use leptos::*;
|
||||
use leptos_router::*;
|
||||
|
||||
use crate::features::navbar_projects::gen::queries::get_projects_list_view::{
|
||||
ResponseData, Variables,
|
||||
@@ -18,7 +17,10 @@ pub async fn get_projects_list() -> anyhow::Result<Vec<GetProjectsListViewGetPro
|
||||
.send()
|
||||
.await?;
|
||||
let response_body: Response<ResponseData> = res.json().await?;
|
||||
Ok(response_body.data.unwrap().get_projects)
|
||||
Ok(response_body
|
||||
.data
|
||||
.ok_or(anyhow::anyhow!("failed to get projects list"))?
|
||||
.get_projects)
|
||||
}
|
||||
|
||||
#[component]
|
||||
@@ -38,7 +40,10 @@ pub fn NavbarProjectsView(
|
||||
.map(|project| {
|
||||
view! { cx,
|
||||
<a href=format!("/dash/project/{}", & project.id) class="project-item">
|
||||
<div class="project-item-name hover:dark:bg-blue-700 rounded-md p-0.5 px-2">
|
||||
|
||||
|
||||
|
||||
<div class="project-item-name hover:dark:bg-blue-700 rounded-md p-0.5 px-2">
|
||||
{&project.name}
|
||||
</div>
|
||||
</a>
|
||||
|
Reference in New Issue
Block a user