feat: with como_web
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-10-21 11:23:11 +02:00
parent 6e16fc6b2b
commit 71b5a63700
48 changed files with 7900 additions and 27 deletions

View File

@@ -0,0 +1 @@
pub mod queries;

View File

@@ -0,0 +1,43 @@
#![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}\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(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,
}
}
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,
}
}
}

View File

@@ -0,0 +1,6 @@
query GetProjectsListView {
getProjects {
id
name
}
}

View File

@@ -0,0 +1,69 @@
use graphql_client::{GraphQLQuery, Response};
use leptos::*;
use crate::features::navbar_projects::gen::queries::get_projects_list_view::{
ResponseData, Variables,
};
use crate::features::navbar_projects::gen::queries::GetProjectsListView;
use super::gen::queries::get_projects_list_view::GetProjectsListViewGetProjects;
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 NavbarProjectsView(
projects: Resource<(), Vec<GetProjectsListViewGetProjects>>,
) -> impl IntoView {
let projects_view = move || {
projects.with(|projects| {
if projects.is_none() {
return Vec::new()
}
let projects = projects.as_ref().unwrap();
if projects.is_empty() {
return vec![view! { <div class="project-item">"No projects"</div> }.into_any()];
}
projects
.into_iter()
.map(|project| {
view! {
<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">
{&project.name}
</div>
</a>
}.into_any()
})
.collect::<Vec<_>>()
})
};
view! { <div class="project-items space-y-1">{projects_view}</div> }
}
#[component]
pub fn NavbarProjects() -> impl IntoView {
let projects =
create_local_resource(|| (), |_| async { get_projects_list().await.unwrap() });
view! { <NavbarProjectsView projects=projects/> }
}