diff --git a/src/.deploy/index.ts b/src/.deploy/index.ts new file mode 100644 index 0000000..4f3eedb --- /dev/null +++ b/src/.deploy/index.ts @@ -0,0 +1 @@ +export * from "./temp-stand"; diff --git a/src/shared/helpers/temp-stand.ts b/src/.deploy/temp-stand.ts similarity index 70% rename from src/shared/helpers/temp-stand.ts rename to src/.deploy/temp-stand.ts index 88d2426..2dfa001 100644 --- a/src/shared/helpers/temp-stand.ts +++ b/src/.deploy/temp-stand.ts @@ -4,14 +4,19 @@ const tempStandRegex = /^(github-client-47c49|dev-github-client)--pr\d+.+\.web\. const isTempStand = () => tempStandRegex.test(window.location.host); +const STAND_URL_ENV = "REACT_APP_DEV_STORAGE_URL"; +const devStorageUrl = process.env[STAND_URL_ENV]; + export const loadLocalStorageFromDevIfNeeded = async () => { - if (!isTempStand()) { + if (!isTempStand() || !devStorageUrl) { + if(!devStorageUrl) { + console.debug(`Note that you need to provide ${STAND_URL_ENV} env to make dev stand work`) + } return; } - // Сделал бы через DefinePlugin, но ради этого делать eject не хочется // @ts-ignore const { default: createGuest } = await import("cross-domain-storage/guest"); - const storage = createGuest("https://dev.github-client.gq/dev/temp-stands.html"); + const storage = createGuest(devStorageUrl); const userCredentialRaw = await new Promise((resolve, reject) => storage.get(CREDENTIAL_KEY, (error: any, data: string | undefined) => { if (error) { diff --git a/src/index.tsx b/src/index.tsx index 2ce9b01..523ac14 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,11 +2,11 @@ import React from "react"; import ReactDOM from "react-dom"; import App from "./app"; import * as serviceWorker from "./serviceWorker"; +import { loadLocalStorageFromDevIfNeeded } from ".deploy"; import "normalize.css"; import "antd/dist/antd.css"; -import { loadLocalStorageFromDevIfNeeded } from "./shared/helpers/temp-stand"; -function init() { +function renderApp() { ReactDOM.render( @@ -15,7 +15,7 @@ function init() { ); } -loadLocalStorageFromDevIfNeeded().then(init); +loadLocalStorageFromDevIfNeeded().then(renderApp); // If you want your app to work offline and load faster, you can change // unregister() to register() below. Note this comes with some pitfalls. diff --git a/src/shared/helpers/index.ts b/src/shared/helpers/index.ts index 8363b8a..e8b17db 100644 --- a/src/shared/helpers/index.ts +++ b/src/shared/helpers/index.ts @@ -1,5 +1,4 @@ import * as str from "./string"; import * as dom from "./dom"; -import * as tempStand from "./temp-stand"; -export { str, dom, tempStand }; +export { str, dom }; diff --git a/src/shared/helpers/xd-local-storage/index.ts b/src/shared/helpers/xd-local-storage/index.ts deleted file mode 100644 index f06f909..0000000 --- a/src/shared/helpers/xd-local-storage/index.ts +++ /dev/null @@ -1,109 +0,0 @@ -import XdUtils from "./services/xd-utils" - -/** - * Created by dagan on 07/04/2014. - */ - -interface xdLocalStorageAPI { - getItem: (key: string, callback: (value: string) => void) => void; -} - -export default (function () { - const MESSAGE_NAMESPACE = "cross-domain-local-message"; - - var defaultData = { - namespace: MESSAGE_NAMESPACE, - }; - - function postData(id: string, data: any) { - var mergedData = XdUtils.extend(data, defaultData); - mergedData.id = id; - window.parent.postMessage(JSON.stringify(mergedData), "*"); - } - - function getData(id: string, key: string) { - var value = localStorage.getItem(key); - var data = { - key: key, - value: value, - }; - postData(id, data); - } - - function setData(id: string, key: string, value: string) { - localStorage.setItem(key, value); - var checkGet = localStorage.getItem(key); - var data = { - success: checkGet === value, - }; - postData(id, data); - } - - function removeData(id: string, key: string) { - localStorage.removeItem(key); - postData(id, {}); - } - - function getKey(id: string, index: number) { - var key = localStorage.key(index); - postData(id, { key: key }); - } - - function getSize(id: string) { - var size = JSON.stringify(localStorage).length; - postData(id, { size: size }); - } - - function getLength(id: string) { - var length = localStorage.length; - postData(id, { length: length }); - } - - function clear(id: string) { - localStorage.clear(); - postData(id, {}); - } - - function receiveMessage(event: any) { - var data; - try { - data = JSON.parse(event.data); - } catch (err) { - //not our message, can ignore - } - - if (data && data.namespace === MESSAGE_NAMESPACE) { - if (data.action === "set") { - setData(data.id, data.key, data.value); - } else if (data.action === "get") { - getData(data.id, data.key); - } else if (data.action === "remove") { - removeData(data.id, data.key); - } else if (data.action === "key") { - getKey(data.id, data.key); - } else if (data.action === "size") { - getSize(data.id); - } else if (data.action === "length") { - getLength(data.id); - } else if (data.action === "clear") { - clear(data.id); - } - } - } - - if (window.addEventListener) { - window.addEventListener("message", receiveMessage, false); - } else { - window.onmessage = receiveMessage; - } - - function sendOnLoad() { - var data = { - namespace: MESSAGE_NAMESPACE, - id: "iframe-ready", - }; - window.parent.postMessage(JSON.stringify(data), "*"); - } - //on creation - sendOnLoad(); -})() as any as xdLocalStorageAPI; diff --git a/src/shared/helpers/xd-local-storage/services/xd-utils.ts b/src/shared/helpers/xd-local-storage/services/xd-utils.ts deleted file mode 100644 index 0432863..0000000 --- a/src/shared/helpers/xd-local-storage/services/xd-utils.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Created by Ofir_Dagan on 4/17/14. - */ - -export default { - extend(object: any, defaultObject: any) { - const result = defaultObject || {}; - for (let key in object) { - if (Object.prototype.hasOwnProperty.call(object, key)) { - result[key] = object[key]; - } - } - return result; - } -} diff --git a/tsconfig.json b/tsconfig.json index 7bd7d27..989911d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,8 +22,5 @@ }, "include": [ "src" - ], - "exclude": [ - "src/shared/helpers/xd-local-storage/index.ts" ] }