From cadc8ac9e3169e9ea9c02df4f3fa86bcdc28f5ab Mon Sep 17 00:00:00 2001 From: Kevin Hill Date: Tue, 15 Oct 2024 06:32:46 -0700 Subject: [PATCH] working on the app cards --- src/hooks/useStore.ts | 77 ++++++++++--------- src/pages/Options/Tabs/ConfigTab.tsx | 6 +- src/pages/Options/components/AppCard.tsx | 45 ++++++----- .../Options/components/AppVisibilityBadge.tsx | 28 +++++++ 4 files changed, 94 insertions(+), 62 deletions(-) create mode 100644 src/pages/Options/components/AppVisibilityBadge.tsx diff --git a/src/hooks/useStore.ts b/src/hooks/useStore.ts index 35c1242..929b263 100644 --- a/src/hooks/useStore.ts +++ b/src/hooks/useStore.ts @@ -1,6 +1,7 @@ import { create } from "zustand"; import { createJSONStorage, persist } from "zustand/middleware"; +import ChromeStateStorage from "@/lib/ChromeStateStorage"; import { DEMO_APPS, INSPECTOR_APP } from "@/lib/EmbeddableApps"; import type { RetoolApp } from "@/types/extension"; @@ -32,7 +33,7 @@ export type Actions = { export const STORAGE_KEY = "app-embedder-for-retool2"; const initialState: State = { - domain: "", + domain: "fortunabmc", isEditing: false, activeAppName: INSPECTOR_APP["name"], workflow: { @@ -43,41 +44,41 @@ const initialState: State = { }; export const useStore = create()( - // persist( - (set, get) => ({ - ...initialState, - reset: () => useStore.setState(initialState), - setDomain: (domain) => set(() => ({ domain })), - setEditMode: (isEditing) => set(() => ({ isEditing })), - setActiveApp: (activeAppName) => set(() => ({ activeAppName })), - addApp: (app) => set((state) => ({ apps: [...state.apps, app] })), - updateApp: (name, props) => { - set((state) => ({ - apps: state.apps.map((app) => { - return app.name === name ? { ...app, ...props } : app; - }), - })); - }, - updateActiveApp: (props) => { - const name = get().activeAppName; - if (name) { - get().updateApp(name, props); - } - }, - updateWorkflow: (props) => { - set((state) => ({ - ...state, - workflow: { ...state.workflow, ...props }, - })); - }, - getActiveApp: () => { - const activeAppName = get().activeAppName; - return get().apps.find((app) => app.name === activeAppName); - }, - }) - // { - // name: STORAGE_KEY, - // storage: createJSONStorage(() => ChromeStateStorage), - // } - // ) + persist( + (set, get) => ({ + ...initialState, + reset: () => set(initialState), + setDomain: (domain) => set(() => ({ domain })), + setEditMode: (isEditing) => set(() => ({ isEditing })), + setActiveApp: (activeAppName) => set(() => ({ activeAppName })), + addApp: (app) => set((state) => ({ apps: [...state.apps, app] })), + updateApp: (name, props) => { + set((state) => ({ + apps: state.apps.map((app) => { + return app.name === name ? { ...app, ...props } : app; + }), + })); + }, + updateActiveApp: (props) => { + const name = get().activeAppName; + if (name) { + get().updateApp(name, props); + } + }, + updateWorkflow: (props) => { + set((state) => ({ + ...state, + workflow: { ...state.workflow, ...props }, + })); + }, + getActiveApp: () => { + const activeAppName = get().activeAppName; + return get().apps.find((app) => app.name === activeAppName); + }, + }), + { + name: STORAGE_KEY, + storage: createJSONStorage(() => ChromeStateStorage), + } + ) ); diff --git a/src/pages/Options/Tabs/ConfigTab.tsx b/src/pages/Options/Tabs/ConfigTab.tsx index 6a3a8cd..aadc413 100644 --- a/src/pages/Options/Tabs/ConfigTab.tsx +++ b/src/pages/Options/Tabs/ConfigTab.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React from "react"; import { Col, Container, Row } from "react-bootstrap"; import { FormProvider, useForm } from "react-hook-form"; @@ -28,9 +28,9 @@ function ConfigTab() { {!isEditing ? ( startEditMode()} /> diff --git a/src/pages/Options/components/AppCard.tsx b/src/pages/Options/components/AppCard.tsx index 83094f0..0591f5d 100644 --- a/src/pages/Options/components/AppCard.tsx +++ b/src/pages/Options/components/AppCard.tsx @@ -8,10 +8,12 @@ import { useEditMode } from "@/hooks/useEditMode"; import { useRetoolAppUrl } from "@/hooks/useRetoolAppUrl"; import { useStore } from "@/hooks/useStore"; +import AppVisibilityBadge from "./AppVisibilityBadge"; + import type { RetoolApp, UrlParam } from "@/types/extension"; type BaseProps = { - app: RetoolApp; + app?: RetoolApp; isActive: boolean; }; @@ -41,40 +43,30 @@ function AppCard({ app, isActive, ...props }: Props) { -
- {app.name} - - {app.version[0] === "l" ? app.version : `v${app.version}`} - -
- - {/* {isActive && ⭐️} */} - {app.env} + {app?.name} + {app?.env}
- - Public App:{" "} - {app.public ? "Yes" : "No"} - - {app.query.length > 0 && ( + {app?.query && (
Query Params
)} - {app.hash.length > 0 && ( + {app?.hash && (
Hash Params
)}
-
-
+
Open in Retool +
+ + +
+
+ + + {app?.version[0] === "l" ? app?.version : `v${app?.version}`} + +
+
- +
); } diff --git a/src/pages/Options/components/AppVisibilityBadge.tsx b/src/pages/Options/components/AppVisibilityBadge.tsx new file mode 100644 index 0000000..956cd70 --- /dev/null +++ b/src/pages/Options/components/AppVisibilityBadge.tsx @@ -0,0 +1,28 @@ +import "./AppCard.css"; + +import React from "react"; +import { Badge } from "react-bootstrap"; + +type Props = { + isPublic?: boolean; +}; + +function AppVisibilityBadge({ isPublic }: Props) { + return ( + + {isPublic ? ( + + + public + + ) : ( + + + private + + )} + + ); +} + +export default AppVisibilityBadge;