Skip to content

Commit 47243ac

Browse files
committed
feat: update tabs
1 parent 15e31a2 commit 47243ac

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

.vscode/settings.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
{
2-
"emmet.includeLanguages": {
3-
"rust": "html",
4-
"*.rs": "html"
5-
},
62
"tailwindCSS.includeLanguages": {
7-
"rust": "rust",
8-
"*.rs": "rust"
9-
},
10-
"files.associations": {
11-
"*.rs": "rust"
3+
"rust": "html"
124
},
135
"editor.quickSuggestions": {
146
"other": "on",

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77
[dependencies]
8-
leptos = { version = "0.6.6", features = ["csr", "nightly"] }
8+
leptos = { version = "0.6.8", features = ["csr", "nightly"] }
99
leptos_devtools = { git = "https://github.com/luoxiaozero/leptos-devtools" }
1010
serde = { version = "1.0.192", features = ["derive"] }
1111
serde-wasm-bindgen = "0.6.3"
@@ -17,7 +17,7 @@ serde_json = "1.0.113"
1717
wasm-bindgen-futures = "0.4.39"
1818
monaco = "0.4.0"
1919
tauri-sys = { git = "https://github.com/JonasKruckenberg/tauri-sys", features = ["all"] }
20-
thaw = { version = "0.2.1", features = ["csr"] }
20+
thaw = { version = "0.2.2", features = ["csr"] }
2121
common = { path = "common" }
2222
futures = "0.3.30"
2323
async-stream = "0.3.5"

src/app.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use leptos::*;
2-
use thaw::{Button, Tab, TabLabel, Tabs};
2+
use leptos_icons::*;
3+
use thaw::{Button, ButtonSize, Tab, TabLabel, Tabs};
34

45
use crate::{
56
enums::QueryTableLayout,
@@ -26,7 +27,7 @@ pub fn App() -> impl IntoView {
2627
provide_context(create_rw_signal(0.0f32));
2728
provide_context(ActiveProjectStore::default());
2829
provide_context(TabsStore::default());
29-
let tabs = use_context::<tabs::TabsStore>().unwrap();
30+
let mut tabs = use_context::<tabs::TabsStore>().unwrap();
3031

3132
view! {
3233
<div class="flex h-screen">
@@ -40,10 +41,16 @@ pub fn App() -> impl IntoView {
4041
children=move |index| {
4142
view! {
4243
<Tab key=index.to_string()>
43-
<TabLabel class="p-0" slot>
44-
<div class="flex flex-row items-center justify-between w-20">
45-
<div>{(index + 1).to_string()}</div>
46-
<button class="rounded-md text-xs">X</button>
44+
<TabLabel slot>
45+
<div class="flex flex-row items-center justify-between gap-2 h-full text-sm">
46+
<span>{format!("Tab {}", (index + 1).to_string())}</span>
47+
<button
48+
class="rounded-full p-1 hover:bg-gray-100"
49+
on:click=move |_| { tabs.remove_editor(index) }
50+
>
51+
52+
<Icon icon=icondata::CgClose width="16" height="16"/>
53+
</button>
4754
</div>
4855
</TabLabel>
4956
<QueryEditor/>
@@ -55,7 +62,9 @@ pub fn App() -> impl IntoView {
5562

5663
</Tabs>
5764
<Button
58-
class="absolute top-2 right-2"
65+
size=ButtonSize::Small
66+
icon=icondata::TbPlus
67+
class="absolute top-2 right-2 text-sm"
5968
on:click=move |_| {
6069
tabs.active_tabs.update(|prev| *prev += 1);
6170
tabs.selected_tab
@@ -69,7 +78,7 @@ pub fn App() -> impl IntoView {
6978
}
7079
>
7180

72-
"+"
81+
{"Add Tab"}
7382
</Button>
7483
</main>
7584
<Footer/>

src/store/tabs.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,21 @@ impl TabsStore {
122122

123123
#[allow(dead_code)]
124124
pub fn remove_editor(&mut self, index: usize) {
125+
if self.active_tabs.get() == 1 {
126+
return;
127+
}
128+
129+
self.active_tabs.update(|prev| {
130+
*prev -= 1;
131+
});
132+
125133
self.editors.update(|prev| {
126134
prev.remove(index);
127135
});
136+
137+
self.sql_results.update(|prev| {
138+
prev.remove(index);
139+
});
128140
}
129141

130142
pub fn select_active_editor(&self) -> ModelCell {
@@ -197,3 +209,4 @@ impl TabsStore {
197209
None
198210
}
199211
}
212+

0 commit comments

Comments
 (0)