Skip to content

Commit 0cc2709

Browse files
authored
feat: rename tabs and UI fix (#15)
1 parent 9dcd0d1 commit 0cc2709

File tree

8 files changed

+122
-54
lines changed

8 files changed

+122
-54
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ jobs:
7676
args: "--target x86_64-apple-darwin"
7777
# - platform: "ubuntu-20.04" # for Tauri v1 you could replace this with ubuntu-20.04.
7878
# args: ""
79-
- platform: "windows-latest"
80-
args: ""
79+
# - platform: "windows-latest"
80+
# args: ""
8181
runs-on: ${{ matrix.platform }}
8282
steps:
8383
- name: Checkout repository

assets/img/app-pulp.png

463 KB
Loading

package-lock.json

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,13 @@
4949
"@actions/github": "^5.1.1",
5050
"@crabnebula/tauri-plugin-drag": "^0.3.1",
5151
"@prisma/client": "^4.9.0",
52-
"@tanstack/solid-table": "^8.10.6",
52+
"@tanstack/solid-table": "^8.17.3",
5353
"@tanstack/solid-virtual": "^3.5.1",
54-
"@tauri-apps/api": "^1.5.1",
54+
"@tauri-apps/api": "^1.5.6 ",
5555
"github": "^14.0.0",
56-
"howler": "^2.2.3",
5756
"lodash-es": "^4.17.21",
5857
"pretty-ms": "^9.0.0",
59-
"solid-heroicons": "^3.1.1",
58+
"solid-heroicons": "^3.2.4",
6059
"solid-js": "^1.8.17",
6160
"solidjs-use": "^2.3.0",
6261
"wavesurfer.js": "^6.6.4"

src/components/Tabs/Tabs.tsx

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import tabsStore from "@/stores/tabsStore/tabsStore";
22
import { Icon } from "solid-heroicons";
33
import { plus, xMark } from "solid-heroicons/outline";
4-
import { Component, FlowComponent, For } from "solid-js";
4+
import { Component, FlowComponent, For, createSignal } from "solid-js";
55
import { Dynamic } from "solid-js/web";
6+
import { useFocus } from "solidjs-use";
67

78
interface Props {
89
setActive: (tabIndex: number) => void;
@@ -13,30 +14,57 @@ interface Props {
1314
const Tabs: FlowComponent<Props, Component<any>> = (props) => {
1415
return (
1516
<>
16-
<div class="tabs tabs-boxed tabs-xs flex items-center rounded-none">
17+
<div class="tabs tabs-boxed tabs-xs flex items-center rounded-none overflow-x-auto flex-nowrap">
1718
<For each={tabsStore.data}>
1819
{(item, index) => {
20+
const [target, setTarget] = createSignal<HTMLInputElement>();
21+
const [, setFocused] = useFocus(target);
22+
const [getRenamingMode, setRenamingMode] = createSignal(false);
23+
1924
return (
20-
<>
21-
<a
22-
onClick={() => props.setActive(index())}
23-
class="tab"
24-
classList={{
25-
"tab-active": item.active,
25+
<a
26+
ondblclick={(event) => {
27+
event.stopPropagation();
28+
setRenamingMode(true);
29+
setFocused(true);
30+
target()?.select();
31+
}}
32+
onClick={() => props.setActive(index())}
33+
class="tab flex-shrink-0"
34+
classList={{
35+
"tab-active": item.active,
36+
}}
37+
>
38+
<label class="input-sizer" data-value={item.name}>
39+
<input
40+
ref={setTarget}
41+
type="text"
42+
value={item.name}
43+
disabled={!getRenamingMode()}
44+
onBlur={() => setRenamingMode(false)}
45+
onInput={(event) => {
46+
tabsStore.rename(index(), event.target.value);
47+
}}
48+
onKeyDown={(event) => {
49+
if (event.key === "Enter") {
50+
event.preventDefault();
51+
setFocused(false);
52+
}
53+
}}
54+
/>
55+
</label>
56+
57+
<button
58+
class="ml-4 currentColor"
59+
onClick={(event) => {
60+
event.stopPropagation();
61+
tabsStore.activateNextOrPreviousTab(index());
62+
tabsStore.closeTab(index());
2663
}}
2764
>
28-
{item.name || `Tab ${index()}`}
29-
<button
30-
class="ml-4 currentColor"
31-
onClick={(event) => {
32-
event.stopPropagation();
33-
tabsStore.closeTab(index());
34-
}}
35-
>
36-
<Icon path={xMark} class="flex-shrink-0 w-4" />
37-
</button>
38-
</a>
39-
</>
65+
<Icon path={xMark} class="flex-shrink-0 w-4" />
66+
</button>
67+
</a>
4068
);
4169
}}
4270
</For>

src/index.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,33 @@ body {
129129
@apply text-base-content/60 whitespace-nowrap text-xs font-bold;
130130
}
131131
}
132+
133+
134+
135+
136+
137+
138+
.input-sizer {
139+
position: relative;
140+
141+
& input,
142+
textarea {
143+
position: absolute;
144+
left: 0;
145+
top: 0;
146+
width: 100%;
147+
appearance: none;
148+
border: none;
149+
background: transparent;
150+
padding: 0;
151+
margin: 0;
152+
outline: none; /* focus:outline-none equivalent */
153+
}
154+
155+
&::after {
156+
content: attr(data-value) ' ';
157+
visibility: hidden;
158+
white-space: pre-wrap;
159+
}
160+
161+
}

src/services/filesServices.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export const getDirectoryFiles: ResourceFetcher<
2525
skip,
2626
});
2727

28-
const response = paddedSplice(prevValue, skip, data);
29-
return response;
28+
return paddedSplice(prevValue, skip, data);
3029
};
3130

3231
export const getMetadataFiles: ResourceFetcher<

src/stores/tabsStore/tabsStore.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const setTabsStore: SetStoreFunction<ITabs[]> = (...args: any[]) => {
1818
};
1919

2020
const addTab = (): void => {
21-
setTabsStore((t) => [
22-
...t,
23-
{ ...cloneDeep(initialSearchStore), name: `Tab ${t.length}` },
21+
setTabsStore((tabs) => [
22+
...tabs,
23+
{ ...cloneDeep(initialSearchStore), name: `Tab ${tabs.length + 1}` },
2424
]);
2525
};
2626

@@ -30,6 +30,12 @@ const closeTab = (tabIndex: number): void => {
3030
});
3131
};
3232

33+
const activateNextOrPreviousTab = (tabIndex: number): void => {
34+
const nextIndex =
35+
tabIndex + 1 < appStore.tabs.length ? tabIndex + 1 : tabIndex - 1;
36+
active(nextIndex);
37+
};
38+
3339
const active = (tabIndex: number): void => {
3440
setTabsStore({}, (_currentTab, [index]) => {
3541
return {
@@ -38,6 +44,10 @@ const active = (tabIndex: number): void => {
3844
});
3945
};
4046

47+
const rename = (tabIndex: number, name: string): void => {
48+
setTabsStore(tabIndex, "name", name);
49+
};
50+
4151
export default {
4252
get data() {
4353
return appStore.tabs;
@@ -46,4 +56,6 @@ export default {
4656
addTab,
4757
active,
4858
closeTab,
59+
activateNextOrPreviousTab,
60+
rename,
4961
};

0 commit comments

Comments
 (0)