Skip to content

Commit

Permalink
Merge pull request #3 from clearfeld/main
Browse files Browse the repository at this point in the history
Tabbar test build
  • Loading branch information
clearfeld authored Jan 4, 2025
2 parents 94a6a95 + 84e044d commit e39f66c
Show file tree
Hide file tree
Showing 21 changed files with 955 additions and 291 deletions.
327 changes: 178 additions & 149 deletions src-tauri/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "construct"
version = "0.2.1"
version = "0.3.0"
description = "A GUI API Client"
authors = ["clearfeld"]
edition = "2021"
Expand Down
14 changes: 13 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::{str, vec};
use url::Url;
use uuid::Uuid;

static mut APP_VERSION: String = String::new();

// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
fn greet(name: &str) -> String {
Expand Down Expand Up @@ -142,7 +144,11 @@ fn http_request(

easy.http_headers(list).unwrap();

easy.useragent("ConstructRuntime/0.1.0").unwrap();
// TODO: FIXME
unsafe {
easy.useragent(&format!("ConstructRuntime/{}", APP_VERSION)).unwrap();
// println!("{}", format!("ConstructRuntime/{}", APP_VERSION));
}

// dirty evil lies that breaks my heart
// easy.accept_encoding("gzip, deflate, br");
Expand Down Expand Up @@ -234,6 +240,12 @@ fn http_request(
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.setup(|app| {
println!("{}", app.package_info().version.to_string());
// TODO: FIXME: use lazy or whatever is the current rust recommendation, so unsafe isnt needed
unsafe { APP_VERSION = app.package_info().version.to_string() };
Ok(())
})
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_updater::Builder::new().build())
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "construct",
"version": "0.2.1",
"version": "0.3.0",
"identifier": "com.construct.app",
"build": {
"beforeDevCommand": "pnpm dev",
Expand Down
2 changes: 2 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ body {
--sidebar-delete-req: #CA3939;
--sidebar-patch-req: #7FC27E;

--tabbar-height: 1.875rem;

--toolbar-width: 2.25rem;
--toolbar-fixed-width: 2.25rem;
/* This won't change */
Expand Down
11 changes: 4 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Routes, Route, Outlet } from "react-router";

import "./updater.tsx";
import { H5 } from "@controlkit/ui";
import TabBar from "./commons/tabbar/index.tsx";

const styles = stylex.create({
container: {
Expand All @@ -28,15 +29,13 @@ const styles = stylex.create({
},

content_width: {
// width: "calc(100% - var(--sidebar-width))",
width: "calc(100%)",
width: "calc(100% - var(--sidebar-width))",
},

details_container: {
display: "flex",
width: "100%",
// height: "calc(100% - 2rem)", // tabbar-height
height: "100%",
height: "calc(100% - var(--tabbar-height))",
},

request_container: {
Expand Down Expand Up @@ -113,8 +112,6 @@ function App() {

<div {...stylex.props(styles.details_container)}>
<div {...stylex.props(styles.request_container)}>
{/* <httprequestspage /> */}

<div
style={{
display: "flex",
Expand Down Expand Up @@ -143,7 +140,7 @@ function App() {
<Sidebar />

<div {...stylex.props(styles.content_width)}>
{/* <TabBar /> */}
<TabBar />

<div {...stylex.props(styles.details_container)}>
<div {...stylex.props(styles.request_container)}>
Expand Down
3 changes: 3 additions & 0 deletions src/assets/arrow-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions src/commons/sidebar/collections/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import useRequestStore from "@src/stores/request_store";

import { UpdateHttpRequestTargetIfExists } from "@src/stores/request_store/sidebar_slice";
import { useEffect } from "react";
import { E_TabStatus } from "@src/stores/request_store/tabbar_slice";

export default function Collections() {
const collection = useRequestStore((state) => state.collection);
Expand All @@ -14,12 +15,20 @@ export default function Collections() {
const addCollection = useRequestStore((state) => state.addCollection);
const setCollection = useRequestStore((state) => state.setCollection);

const getTabs = useRequestStore((state) => state.getTabs);
const setTabs = useRequestStore((state) => state.setTabs);

const getCurrentRequest= useRequestStore((state) => state.getCurrentRequest);

const getId = useRequestStore((state) => state.getId);
const getName = useRequestStore((state) => state.getName);
const getUrl = useRequestStore((state) => state.getUrl);
const getMethod = useRequestStore((state) => state.getMethod);
const getHeaders = useRequestStore((state) => state.getHeaders);
const getBody = useRequestStore((state) => state.getBody);

const setTabState = useRequestStore((state) => state.setTabState);

useEffect(() => {
SetupShortcuts();

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

// TODO: add switch statement for different types of tabs / sidebar items
// defaulting to HTTP_REQUEST

const ns = structuredClone(getCollection());
// debugger;

UpdateHttpRequestTargetIfExists(
ns,
getId(),
getName(),
getUrl(),
getMethod(),
getHeaders(),
getBody(),
);

setCollection(ns);

const tabs = [ ...getTabs() ];

const id = getId();
for(let i = 0; i < tabs.length; ++i) {
if(tabs[i].id === id) {
tabs[i].title = getName();
tabs[i].requestType = getMethod().value;
tabs[i].status = E_TabStatus.SAVED;

tabs[i].data = getCurrentRequest();

break;
}
}

setTabs(tabs);

setTabState(id, E_TabStatus.SAVED);
}

return (
Expand Down
81 changes: 80 additions & 1 deletion src/commons/sidebar/collections/recursive_tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,30 @@ import {
Label,
} from "@controlkit/ui";

import {
E_TabStatus,
E_TabType,
type T_Tab,
} from "@src/stores/request_store/tabbar_slice";

const styles = stylex.create({
row: {
padding: "0.0625rem 0",

cursor: "pointer",

borderLeft: "0.125rem solid transparent",

// transition: "background-color var(--transition-speed) ease",

":hover": {
backgroundColor: "#0E0F10",
},
},

rowActive: {
backgroundColor: "#1F252D",
borderLeft: "0.125rem solid #2558BC",
},
});

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

const getTabs = useRequestStore((state) => state.getTabs);
const setTabs = useRequestStore((state) => state.setTabs);

const activeTab = useRequestStore((state) => state.activeTab);
const setActiveTab = useRequestStore((state) => state.setActiveTab);

// const setTabState = useRequestStore((state) => state.setTabState);

// TODO: remove this when moving the sub comps into their own files
const [_isHoveredFolder, setIsHoveredFolder] = useState<boolean>(false);
const [_isHoveredOther, setIsHoveredOther] = useState<boolean>(false);
Expand Down Expand Up @@ -587,7 +606,12 @@ export default function RecursiveTree(props: any) {
return (
// biome-ignore lint/a11y/useKeyWithClickEvents: <explanation>
<div key={item.id}>
<div {...stylex.props(styles.row)}>
<div
{...stylex.props(
styles.row,
activeTab === item.id && styles.rowActive,
)}
>
<div
style={{
display: "grid",
Expand Down Expand Up @@ -615,6 +639,37 @@ export default function RecursiveTree(props: any) {

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


const tabs = [...getTabs()];

const tab = tabs.find((t) => t.id === item.id);
// const status = tab?.status ?? E_TabStatus.NONE;

if (tab) {
// setTabState(item.id, status);
// setTimeout(() => {
// setTabState(item.id, status);
// // setTabState(item.id, E_TabStatus.SAVED);
// }, 100);

const method = methods.find((method) => method.value === tab.data.method);

setRequestParameters(
tab.data.id,
tab.data.name,
tab.data.url,
method ?? methods[0],
tab.data.autoHeaders ?? autoHeaders, // [], // item.autoHeaders,
tab.data.headers,
tab.data.body,
// item.cookies,
);

setActiveTab(item.id);

// return;
} else {

setRequestParameters(
item.id,
item.name,
Expand All @@ -626,6 +681,30 @@ export default function RecursiveTree(props: any) {
// item.cookies,
);

const t: T_Tab = {
id: item.id,
status: E_TabStatus.NONE,
title: item.name,
type: E_TabType.HTTP_REQUEST,
requestType: item.method,
data: {
id: item.id,
name: item.name,
url: item.url,
method: item.method,
autoHeaders: item.autoHeaders,
headers: item.headers,
body: item.body,

response: null,
response_headers: null,
},
};
tabs.push(t);
setTabs(tabs);

setActiveTab(item.id);
}
// toggleField(item.id, "open", !item.open);
}}
onMouseEnter={(e) => {
Expand Down
Loading

0 comments on commit e39f66c

Please sign in to comment.