Skip to content

Commit

Permalink
working on the app cards
Browse files Browse the repository at this point in the history
  • Loading branch information
khill-fbmc committed Oct 15, 2024
1 parent 21d9bbb commit cadc8ac
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 62 deletions.
77 changes: 39 additions & 38 deletions src/hooks/useStore.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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: {
Expand All @@ -43,41 +44,41 @@ const initialState: State = {
};

export const useStore = create<State & Actions>()(
// 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),
}
)
);
6 changes: 3 additions & 3 deletions src/pages/Options/Tabs/ConfigTab.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -28,9 +28,9 @@ function ConfigTab() {
{!isEditing ? (
<Container className="pt-2">
<AppCard
isActive={false}
isActive
editable
app={app!}
app={app}
onEdit={() => startEditMode()}
/>
</Container>
Expand Down
45 changes: 24 additions & 21 deletions src/pages/Options/components/AppCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -41,40 +43,30 @@ function AppCard({ app, isActive, ...props }: Props) {
<Card.Header
className={clsx(
"d-flex justify-content-between align-items-center",
isActive && `bg-${app.env}`
isActive && `bg-${app?.env}`,
isActive && app?.env === "production" && "text-white",
isActive && app?.env === "development" && "text-white"
)}
>
<div className="d-flex gap-2 align-items-center">
{app.name}
<Badge pill bg="secondary">
{app.version[0] === "l" ? app.version : `v${app.version}`}
</Badge>
</div>

{/* {isActive && <span className="ml-auto">⭐️</span>} */}
<span className={clsx("badge", `bg-${app.env}`)}>{app.env}</span>
{app?.name}
<span className={clsx("badge", `bg-${app?.env}`)}>{app?.env}</span>
</Card.Header>
<Card.Body>
<Card.Text>
Public App:{" "}
<span className="text-muted">{app.public ? "Yes" : "No"}</span>
</Card.Text>
<Row>
{app.query.length > 0 && (
{app?.query && (
<Col>
<h5>Query Params</h5>
<Parameters type="query" params={app.query} />
</Col>
)}
{app.hash.length > 0 && (
{app?.hash && (
<Col>
<h5>Hash Params</h5>
<Parameters type="hash" params={app.hash} />
</Col>
)}
</Row>
<br />
<div className="d-flex justify-space-between">
<div className="d-flex my-2 justify-content-center">
<a
target="_blank"
rel="noreferrer"
Expand All @@ -83,14 +75,25 @@ function AppCard({ app, isActive, ...props }: Props) {
>
<i className="bi bi-box-arrow-up-right"></i>Open in Retool
</a>
</div>
</Card.Body>
<Card.Footer>
<div className="d-flex justify-space-between">
<div className="d-flex gap-2 align-items-center">
<AppVisibilityBadge isPublic={app?.public} />
<Badge pill bg="secondary">
{app?.version[0] === "l" ? app?.version : `v${app?.version}`}
</Badge>
</div>

<Button
className="btn-sm ms-auto"
onClick={() => {
if (props.editable) {
props.onEdit();
} else {
endEditMode();
setActiveApp(app.name);
setActiveApp(app?.name);
}
}}
variant={
Expand All @@ -104,7 +107,7 @@ function AppCard({ app, isActive, ...props }: Props) {
{props.editable ? "Edit" : isActive ? "⭐️ Active" : "Activate"}
</Button>
</div>
</Card.Body>
</Card.Footer>
</Card>
);
}
Expand Down
28 changes: 28 additions & 0 deletions src/pages/Options/components/AppVisibilityBadge.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Badge pill bg="secondary">
{isPublic ? (
<span className="d-inline-flex gap-1">
<i className="bi bi-share-fill"></i>
public
</span>
) : (
<span className="d-inline-flex gap-1">
<i className="bi bi-shield-shaded"></i>
private
</span>
)}
</Badge>
);
}

export default AppVisibilityBadge;

0 comments on commit cadc8ac

Please sign in to comment.