Skip to content

Commit

Permalink
getting stuck on the implementation of editing an app...
Browse files Browse the repository at this point in the history
  • Loading branch information
khill-fbmc committed Oct 3, 2024
1 parent dca50e0 commit 681d99d
Show file tree
Hide file tree
Showing 19 changed files with 474 additions and 254 deletions.
23 changes: 23 additions & 0 deletions src/hooks/useAppUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useExtensionState } from "./useExtensionState";

import type { RetoolApp } from "../types";

export function useAppUrl(app: RetoolApp) {
const domain = useExtensionState((s) => s.domain);

const base = `https://${domain}.retool.com/`;
const path = `${app.public ? "p" : "app"}/${app.name}`;
const url = new URL(path, base);

app.query.forEach((q) => url.searchParams.append(q.param, q.value));

if (app.hash.length === 0) {
return `${url.toString()}`;
}

const hashParams = new URLSearchParams(
app.hash.map((h) => [h.param, h.value])
);

return `${url.toString()}#${hashParams.toString()}`;
}
2 changes: 1 addition & 1 deletion src/hooks/useExtensionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createJSONStorage, persist } from "zustand/middleware";
import ChromeStateStorage from "@/lib/ChromeStateStorage";
import { DEMO_APPS, INSPECTOR_APP } from "@/lib/EmbeddableApps";

import type { RetoolApp } from "@/types";
import type { RetoolApp } from "@/types/extension";

type State = {
domain: string;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useRetoolAppStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { create } from "zustand";

import type { RetoolApp, UrlParamSpec } from "../types";
import type { RetoolApp, UrlParamSpec } from "../types/extension";

type Actions = {
setAppName: (name: string) => void;
Expand Down
23 changes: 0 additions & 23 deletions src/hooks/useThrottle.ts

This file was deleted.

5 changes: 4 additions & 1 deletion src/lib/ChromeStateStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ function runtimePromise<T = unknown>(handler: PromiseHandler<T>): Promise<T> {

type Resolver<T> = (value: T | PromiseLike<T>) => void;

type PromiseHandler<T> = (resolve: Resolver<T>, rejectIfRuntimeError: () => void) => void;
type PromiseHandler<T> = (
resolve: Resolver<T>,
rejectIfRuntimeError: () => void
) => void;
16 changes: 13 additions & 3 deletions src/lib/ChromeStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ export class ChromeStorage<T extends Options> {
reject(e);
}
return promise.then((saved) => {
chrome.runtime.sendMessage({ source: "storage", event: "update", data: saved });
chrome.runtime.sendMessage({
source: "storage",
event: "update",
data: saved,
});
});
}

public async load(): Promise<T> {
const { promise, resolve, reject } = Promise.withResolvers<T>();
try {
chrome.storage.sync.get(undefined, (saved: Options) => resolve(saved as T));
chrome.storage.sync.get(undefined, (saved: Options) =>
resolve(saved as T)
);
} catch (e) {
reject(e);
}
Expand All @@ -48,7 +54,11 @@ export class ChromeStorage<T extends Options> {

private _handleMessage(message: any) {
const msg = message as StorageUpdated<T>;
if (msg?.source === "storage" && msg?.event === "update" && this._updateHandler) {
if (
msg?.source === "storage" &&
msg?.event === "update" &&
this._updateHandler
) {
this._updateHandler(msg.data);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/EmbeddableApps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RetoolApp } from "../../types";
import type { RetoolApp } from "@/types";

export const INSPECTOR_APP: RetoolApp = {
name: "app-embedder-for-retool-inspector",
Expand Down
120 changes: 0 additions & 120 deletions src/lib/RetoolURL.ts

This file was deleted.

Loading

0 comments on commit 681d99d

Please sign in to comment.