Skip to content

Commit e39f66c

Browse files
authored
Merge pull request #3 from clearfeld/main
Tabbar test build
2 parents 94a6a95 + 84e044d commit e39f66c

File tree

21 files changed

+955
-291
lines changed

21 files changed

+955
-291
lines changed

src-tauri/Cargo.lock

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

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "construct"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
description = "A GUI API Client"
55
authors = ["clearfeld"]
66
edition = "2021"

src-tauri/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use std::{str, vec};
66
use url::Url;
77
use uuid::Uuid;
88

9+
static mut APP_VERSION: String = String::new();
10+
911
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
1012
#[tauri::command]
1113
fn greet(name: &str) -> String {
@@ -142,7 +144,11 @@ fn http_request(
142144

143145
easy.http_headers(list).unwrap();
144146

145-
easy.useragent("ConstructRuntime/0.1.0").unwrap();
147+
// TODO: FIXME
148+
unsafe {
149+
easy.useragent(&format!("ConstructRuntime/{}", APP_VERSION)).unwrap();
150+
// println!("{}", format!("ConstructRuntime/{}", APP_VERSION));
151+
}
146152

147153
// dirty evil lies that breaks my heart
148154
// easy.accept_encoding("gzip, deflate, br");
@@ -234,6 +240,12 @@ fn http_request(
234240
#[cfg_attr(mobile, tauri::mobile_entry_point)]
235241
pub fn run() {
236242
tauri::Builder::default()
243+
.setup(|app| {
244+
println!("{}", app.package_info().version.to_string());
245+
// TODO: FIXME: use lazy or whatever is the current rust recommendation, so unsafe isnt needed
246+
unsafe { APP_VERSION = app.package_info().version.to_string() };
247+
Ok(())
248+
})
237249
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
238250
.plugin(tauri_plugin_process::init())
239251
.plugin(tauri_plugin_updater::Builder::new().build())

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
33
"productName": "construct",
4-
"version": "0.2.1",
4+
"version": "0.3.0",
55
"identifier": "com.construct.app",
66
"build": {
77
"beforeDevCommand": "pnpm dev",

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: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Routes, Route, Outlet } from "react-router";
1515

1616
import "./updater.tsx";
1717
import { H5 } from "@controlkit/ui";
18+
import TabBar from "./commons/tabbar/index.tsx";
1819

1920
const styles = stylex.create({
2021
container: {
@@ -28,15 +29,13 @@ const styles = stylex.create({
2829
},
2930

3031
content_width: {
31-
// width: "calc(100% - var(--sidebar-width))",
32-
width: "calc(100%)",
32+
width: "calc(100% - var(--sidebar-width))",
3333
},
3434

3535
details_container: {
3636
display: "flex",
3737
width: "100%",
38-
// height: "calc(100% - 2rem)", // 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)