-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
editing, saving, canceling; moving things around
- Loading branch information
1 parent
594563e
commit 0b417dd
Showing
20 changed files
with
216 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { useStore } from "./useStore"; | ||
|
||
export function useActiveApp() { | ||
const apps = useStore((s) => s.apps); | ||
const activeAppName = useStore((s) => s.activeAppName); | ||
|
||
return apps.find((app) => app.name === activeAppName); | ||
const getActiveApp = useStore((s) => s.getActiveApp); | ||
const updateActiveApp = useStore((s) => s.updateActiveApp); | ||
const app = getActiveApp(); | ||
return [app, updateActiveApp] as const; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useStore } from "./useStore"; | ||
|
||
export function useAppList() { | ||
const apps = useStore((s) => s.apps); | ||
const addApp = useStore((s) => s.addApp); | ||
const removeApp = useStore((s) => s.removeApp); | ||
const updateApp = useStore((s) => s.updateApp); | ||
|
||
return { | ||
apps, | ||
addApp, | ||
removeApp, | ||
updateApp, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useStore } from "./useStore"; | ||
|
||
export function useTabs() { | ||
const currentTab = useStore((s) => s.currentTab); | ||
const setCurrentTab = useStore((s) => s.setActiveTab); | ||
return [currentTab, setCurrentTab] as const; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,39 @@ | ||
import { useState } from "react"; | ||
import useSWR from "swr"; | ||
|
||
import type { RetoolApp } from "@/types/extension"; | ||
|
||
export function useWorkflow(url: string, apiKey: string) { | ||
const [workflowUrl, setWorkflowUrl] = useState<string>(url); | ||
const [workflowApiKey, setWorkflowApiKey] = useState<string>(apiKey); | ||
export function useWorkflowData(apiKey: string, id: string) { | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [workflowData, setWorkflowData] = useState<RetoolApp[]>([]); | ||
const [workflowError, setWorkflowError] = useState<string | undefined>(); | ||
|
||
const fetchWorkflowData = async () => { | ||
setIsLoading(true); | ||
try { | ||
const url = `https://api.retool.com/v1/workflows/${id}/startTrigger`; | ||
const res = await fetch(url, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"X-Workflow-Api-Key": apiKey, | ||
}, | ||
}); | ||
|
||
const result = (await res.json()) as { apps: RetoolApp[] }; | ||
|
||
setWorkflowData(result?.apps); | ||
} catch (e) { | ||
setWorkflowError((e as Error).message); | ||
} | ||
setIsLoading(false); | ||
}; | ||
|
||
return { | ||
state: { | ||
workflowUrl, | ||
workflowApiKey, | ||
fetchWorkflowData, | ||
workflow: { | ||
isLoading, | ||
data: workflowData, | ||
error: workflowError, | ||
}, | ||
setWorkflowUrl, | ||
setWorkflowApiKey, | ||
...useSWR<WorkflowResult>(url, () => callWorkflow(url, workflowApiKey)), | ||
}; | ||
} | ||
|
||
async function callWorkflow( | ||
url: string, | ||
workflowApiKey: string | ||
): Promise<WorkflowResult> { | ||
const res = await fetch(url, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"X-Workflow-Api-Key": workflowApiKey, | ||
}, | ||
}); | ||
|
||
const data = (await res.json()) as { apps: RetoolApp[] }; | ||
|
||
if (!data?.apps) { | ||
throw new Error( | ||
"The returned object from the workflow must have `apps` as a property." | ||
); | ||
} | ||
|
||
return { apps: data.apps }; | ||
} | ||
|
||
type WorkflowResult = { | ||
apps: RetoolApp[]; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.