Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: split lens manager into installed/uninstalled tabs #143

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions crates/client/public/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,10 @@ Ensure the default browser behavior of the `hidden` attribute.
cursor: pointer;
}

.list-none {
list-style-type: none;
}

.flex-row {
flex-direction: row;
}
Expand Down Expand Up @@ -804,6 +808,15 @@ Ensure the default browser behavior of the `hidden` attribute.
border-color: rgb(28 25 23 / var(--tw-border-opacity));
}

.border-green-500 {
--tw-border-opacity: 1;
border-color: rgb(34 197 94 / var(--tw-border-opacity));
}

.border-transparent {
border-color: transparent;
}

.border-stone-800 {
--tw-border-opacity: 1;
border-color: rgb(41 37 36 / var(--tw-border-opacity));
Expand Down Expand Up @@ -898,21 +911,26 @@ Ensure the default browser behavior of the `hidden` attribute.
padding-right: 0.5rem;
}

.py-4 {
padding-top: 1rem;
padding-bottom: 1rem;
}

.px-8 {
padding-left: 2rem;
padding-right: 2rem;
}

.px-4 {
padding-left: 1rem;
padding-right: 1rem;
}

.py-2 {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}

.py-4 {
padding-top: 1rem;
padding-bottom: 1rem;
}

.pl-1 {
padding-left: 0.25rem;
}
Expand All @@ -925,6 +943,14 @@ Ensure the default browser behavior of the `hidden` attribute.
padding-left: 1rem;
}

.pt-4 {
padding-top: 1rem;
}

.pb-4 {
padding-bottom: 1rem;
}

.pb-2 {
padding-bottom: 0.5rem;
}
Expand Down Expand Up @@ -980,6 +1006,10 @@ Ensure the default browser behavior of the `hidden` attribute.
line-height: 1;
}

.font-medium {
font-weight: 500;
}

.font-bold {
font-weight: 700;
}
Expand Down Expand Up @@ -1046,6 +1076,11 @@ Ensure the default browser behavior of the `hidden` attribute.
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
}

.hover\:border-green-500:hover {
--tw-border-opacity: 1;
border-color: rgb(34 197 94 / var(--tw-border-opacity));
}

.hover\:bg-neutral-600:hover {
--tw-bg-opacity: 1;
background-color: rgb(82 82 82 / var(--tw-bg-opacity));
Expand Down
77 changes: 75 additions & 2 deletions crates/client/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,89 @@ pub struct HeaderProps {
pub label: String,
#[prop_or_default]
pub children: Children,
#[prop_or_default]
pub tabs: Html,
}

#[function_component(Header)]
pub fn header(props: &HeaderProps) -> Html {
html! {
<div class="py-4 px-8 top-0 sticky bg-stone-800 z-400 border-b-2 border-stone-900">
<div class="flex flex-row items-center gap-4">
<div class={classes!("pt-4", "px-8", "top-0", "sticky", "bg-stone-800", "z-400", "border-b-2", "border-stone-900")}>
<div class="flex flex-row items-center gap-4 pb-4">
<h1 class="text-2xl grow">{props.label.clone()}</h1>
{props.children.clone()}
</div>
<div class="flex flex-row items-center gap-4">
{props.tabs.clone()}
</div>
</div>
}
}

#[derive(Debug)]
pub struct TabEvent {
pub tab_idx: usize,
pub tab_name: String,
}

#[derive(PartialEq, Properties)]
pub struct TabsProps {
#[prop_or_default]
pub onchange: Callback<TabEvent>,
pub tabs: Vec<String>,
}

#[function_component(Tabs)]
pub fn tabs(props: &TabsProps) -> Html {
let active_idx = use_state_eq(|| 0);
let tab_styles = classes!(
"block",
"border-b-2",
"px-4",
"py-2",
"text-xs",
"font-medium",
"uppercase",
"hover:bg-stone-700",
"hover:border-green-500",
);

let onchange = props.onchange.clone();
let tabs = props.tabs.clone();
use_effect_with_deps(
move |updated| {
onchange.emit(TabEvent {
tab_idx: **updated,
tab_name: tabs[**updated].clone(),
});
|| {}
},
active_idx.clone(),
);

html! {
<ul class="flex flex-row list-none gap-4">
{
props.tabs.iter().enumerate().map(|(idx, tab_name)| {
let border = if idx == *active_idx { "border-green-500" } else { "border-transparent" };
let active_idx = active_idx.clone();
let onclick = Callback::from(move |_| {
active_idx.set(idx);
});

html! {
<li>
<button
onclick={onclick}
class={classes!(tab_styles.clone(), border)}
>
{tab_name}
</button>
</li>
}
})
.collect::<Html>()
}
</ul>
}
}
44 changes: 30 additions & 14 deletions crates/client/src/pages/lens_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use wasm_bindgen_futures::spawn_local;
use yew::function_component;
use yew::prelude::*;

use crate::components::{btn::Btn, icons, Header};
use crate::components::{btn::Btn, icons, Header, TabEvent, Tabs};
use crate::listen;
use crate::utils::RequestState;
use crate::{install_lens, invoke};
Expand Down Expand Up @@ -170,6 +170,7 @@ pub fn lens_component(props: &LensProps) -> Html {

#[function_component(LensManagerPage)]
pub fn lens_manager_page() -> Html {
let active_tab = use_state_eq(|| 0);
let user_installed: UseStateHandle<Vec<LensResult>> = use_state_eq(Vec::new);
let installable: UseStateHandle<Vec<LensResult>> = use_state_eq(Vec::new);

Expand Down Expand Up @@ -226,19 +227,26 @@ pub fn lens_manager_page() -> Html {
}

let contents = if ui_req_state.is_done() && i_req_state.is_done() {
html! {
<>
{
user_installed.iter().map(|data| {
html! {<Lens result={data.clone()} is_installed={true} /> }
}).collect::<Html>()
}
{
installable.iter().map(|data| {
html! {<Lens result={data.clone()} is_installed={false} /> }
}).collect::<Html>()
if *active_tab == 0 {
html! {
<>
{
user_installed.iter().map(|data| {
html! {<Lens result={data.clone()} is_installed={true} /> }
}).collect::<Html>()
}
</>
}
} else {
html! {
<>
{
installable.iter().map(|data| {
html! {<Lens result={data.clone()} is_installed={false} /> }
}).collect::<Html>()
}
</>
}
}
} else {
html! {
Expand All @@ -250,9 +258,17 @@ pub fn lens_manager_page() -> Html {
}
};

let handle_tab_change = Callback::from(move |evnt: TabEvent| {
active_tab.set(evnt.tab_idx);
});

let tabs = html! {
<Tabs onchange={handle_tab_change} tabs={vec!["Installed".to_string(), "Uninstalled".to_string()]} />
};

html! {
<div class="text-white">
<Header label="Lens Manager">
<div class="text-white relative">
<Header label="Lens Manager" tabs={tabs}>
<Btn onclick={on_open_folder}>
<icons::FolderOpenIcon />
<div class="ml-2">{"Lens folder"}</div>
Expand Down