Skip to content

Commit 84e044d

Browse files
committed
Add: UNSTABLE Tabbar - tab state persistence is unstable ie headers and url row
1 parent 5dbc91b commit 84e044d

18 files changed

Lines changed: 934 additions & 285 deletions

File tree

src-tauri/Cargo.lock

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

src/App.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ body {
4343
--sidebar-delete-req: #CA3939;
4444
--sidebar-patch-req: #7FC27E;
4545

46+
--tabbar-height: 1.875rem;
47+
4648
--toolbar-width: 2.25rem;
4749
--toolbar-fixed-width: 2.25rem;
4850
/* This won't change */

src/App.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ const styles = stylex.create({
3535
details_container: {
3636
display: "flex",
3737
width: "100%",
38-
// height: "calc(100% - var(--tabbar-height))",
39-
height: "100%",
38+
height: "calc(100% - var(--tabbar-height))",
4039
},
4140

4241
request_container: {
@@ -113,8 +112,6 @@ function App() {
113112

114113
<div {...stylex.props(styles.details_container)}>
115114
<div {...stylex.props(styles.request_container)}>
116-
{/* <httprequestspage /> */}
117-
118115
<div
119116
style={{
120117
display: "flex",
@@ -143,7 +140,7 @@ function App() {
143140
<Sidebar />
144141

145142
<div {...stylex.props(styles.content_width)}>
146-
{/* <TabBar /> */}
143+
<TabBar />
147144

148145
<div {...stylex.props(styles.details_container)}>
149146
<div {...stylex.props(styles.request_container)}>

src/assets/arrow-left.svg

Lines changed: 3 additions & 0 deletions
Loading

src/commons/sidebar/collections/index.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import useRequestStore from "@src/stores/request_store";
66

77
import { UpdateHttpRequestTargetIfExists } from "@src/stores/request_store/sidebar_slice";
88
import { useEffect } from "react";
9+
import { E_TabStatus } from "@src/stores/request_store/tabbar_slice";
910

1011
export default function Collections() {
1112
const collection = useRequestStore((state) => state.collection);
@@ -14,12 +15,20 @@ export default function Collections() {
1415
const addCollection = useRequestStore((state) => state.addCollection);
1516
const setCollection = useRequestStore((state) => state.setCollection);
1617

18+
const getTabs = useRequestStore((state) => state.getTabs);
19+
const setTabs = useRequestStore((state) => state.setTabs);
20+
21+
const getCurrentRequest= useRequestStore((state) => state.getCurrentRequest);
22+
1723
const getId = useRequestStore((state) => state.getId);
24+
const getName = useRequestStore((state) => state.getName);
1825
const getUrl = useRequestStore((state) => state.getUrl);
1926
const getMethod = useRequestStore((state) => state.getMethod);
2027
const getHeaders = useRequestStore((state) => state.getHeaders);
2128
const getBody = useRequestStore((state) => state.getBody);
2229

30+
const setTabState = useRequestStore((state) => state.setTabState);
31+
2332
useEffect(() => {
2433
SetupShortcuts();
2534

@@ -48,19 +57,42 @@ export default function Collections() {
4857
function SyncHTTPRequestStateToSidebar() {
4958
// console.log("Shortcut triggered");
5059

60+
// TODO: add switch statement for different types of tabs / sidebar items
61+
// defaulting to HTTP_REQUEST
62+
5163
const ns = structuredClone(getCollection());
5264
// debugger;
5365

5466
UpdateHttpRequestTargetIfExists(
5567
ns,
5668
getId(),
69+
getName(),
5770
getUrl(),
5871
getMethod(),
5972
getHeaders(),
6073
getBody(),
6174
);
6275

6376
setCollection(ns);
77+
78+
const tabs = [ ...getTabs() ];
79+
80+
const id = getId();
81+
for(let i = 0; i < tabs.length; ++i) {
82+
if(tabs[i].id === id) {
83+
tabs[i].title = getName();
84+
tabs[i].requestType = getMethod().value;
85+
tabs[i].status = E_TabStatus.SAVED;
86+
87+
tabs[i].data = getCurrentRequest();
88+
89+
break;
90+
}
91+
}
92+
93+
setTabs(tabs);
94+
95+
setTabState(id, E_TabStatus.SAVED);
6496
}
6597

6698
return (

src/commons/sidebar/collections/recursive_tree.tsx

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,30 @@ import {
2121
Label,
2222
} from "@controlkit/ui";
2323

24+
import {
25+
E_TabStatus,
26+
E_TabType,
27+
type T_Tab,
28+
} from "@src/stores/request_store/tabbar_slice";
29+
2430
const styles = stylex.create({
2531
row: {
2632
padding: "0.0625rem 0",
2733

2834
cursor: "pointer",
2935

36+
borderLeft: "0.125rem solid transparent",
37+
38+
// transition: "background-color var(--transition-speed) ease",
39+
3040
":hover": {
3141
backgroundColor: "#0E0F10",
3242
},
3343
},
3444

3545
rowActive: {
3646
backgroundColor: "#1F252D",
47+
borderLeft: "0.125rem solid #2558BC",
3748
},
3849
});
3950

@@ -98,6 +109,14 @@ export default function RecursiveTree(props: any) {
98109
(state) => state.setRequestParameters,
99110
);
100111

112+
const getTabs = useRequestStore((state) => state.getTabs);
113+
const setTabs = useRequestStore((state) => state.setTabs);
114+
115+
const activeTab = useRequestStore((state) => state.activeTab);
116+
const setActiveTab = useRequestStore((state) => state.setActiveTab);
117+
118+
// const setTabState = useRequestStore((state) => state.setTabState);
119+
101120
// TODO: remove this when moving the sub comps into their own files
102121
const [_isHoveredFolder, setIsHoveredFolder] = useState<boolean>(false);
103122
const [_isHoveredOther, setIsHoveredOther] = useState<boolean>(false);
@@ -587,7 +606,12 @@ export default function RecursiveTree(props: any) {
587606
return (
588607
// biome-ignore lint/a11y/useKeyWithClickEvents: <explanation>
589608
<div key={item.id}>
590-
<div {...stylex.props(styles.row)}>
609+
<div
610+
{...stylex.props(
611+
styles.row,
612+
activeTab === item.id && styles.rowActive,
613+
)}
614+
>
591615
<div
592616
style={{
593617
display: "grid",
@@ -615,6 +639,37 @@ export default function RecursiveTree(props: any) {
615639

616640
navigate(`/http_request/${item.id}`);
617641

642+
643+
const tabs = [...getTabs()];
644+
645+
const tab = tabs.find((t) => t.id === item.id);
646+
// const status = tab?.status ?? E_TabStatus.NONE;
647+
648+
if (tab) {
649+
// setTabState(item.id, status);
650+
// setTimeout(() => {
651+
// setTabState(item.id, status);
652+
// // setTabState(item.id, E_TabStatus.SAVED);
653+
// }, 100);
654+
655+
const method = methods.find((method) => method.value === tab.data.method);
656+
657+
setRequestParameters(
658+
tab.data.id,
659+
tab.data.name,
660+
tab.data.url,
661+
method ?? methods[0],
662+
tab.data.autoHeaders ?? autoHeaders, // [], // item.autoHeaders,
663+
tab.data.headers,
664+
tab.data.body,
665+
// item.cookies,
666+
);
667+
668+
setActiveTab(item.id);
669+
670+
// return;
671+
} else {
672+
618673
setRequestParameters(
619674
item.id,
620675
item.name,
@@ -626,6 +681,30 @@ export default function RecursiveTree(props: any) {
626681
// item.cookies,
627682
);
628683

684+
const t: T_Tab = {
685+
id: item.id,
686+
status: E_TabStatus.NONE,
687+
title: item.name,
688+
type: E_TabType.HTTP_REQUEST,
689+
requestType: item.method,
690+
data: {
691+
id: item.id,
692+
name: item.name,
693+
url: item.url,
694+
method: item.method,
695+
autoHeaders: item.autoHeaders,
696+
headers: item.headers,
697+
body: item.body,
698+
699+
response: null,
700+
response_headers: null,
701+
},
702+
};
703+
tabs.push(t);
704+
setTabs(tabs);
705+
706+
setActiveTab(item.id);
707+
}
629708
// toggleField(item.id, "open", !item.open);
630709
}}
631710
onMouseEnter={(e) => {

0 commit comments

Comments
 (0)