Skip to content

Commit

Permalink
Merge pull request #147 from niyazm524/feature/temp_stands
Browse files Browse the repository at this point in the history
Finally (сколько можно): работающие temp-стенды [2]
  • Loading branch information
niyazm524 authored Nov 27, 2020
2 parents 61010c6 + 0dd7777 commit 2d4568e
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ REACT_APP_FIREBASE_projectId=github-client-47c49
REACT_APP_FIREBASE_storageBucket=github-client-47c49.appspot.com
REACT_APP_FIREBASE_messagingSenderId=14406286286
REACT_APP_FIREBASE_appId=1:14406286286:web:58c7c11c2762d36a55c99f

REACT_APP_DEV_STORAGE_URL=https://dev.github-client.gq/dev/temp-stands.html
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@types/react-dom": "^16.9.8",
"antd": "^4.8.5",
"classnames": "^2.2.6",
"cross-domain-storage": "^2.0.7",
"dayjs": "^1.9.6",
"firebase": "^8.0.1",
"graphql": "^15.3.0",
Expand Down
162 changes: 162 additions & 0 deletions public/dev/main.306cbe88.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/dev/temp-stands.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html lang="ru"><head><meta charset="UTF-8"><title>Dev stands helper</title><script src="main.306cbe88.js"></script></head><body> </body></html>
1 change: 1 addition & 0 deletions src/.deploy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./temp-stand";
32 changes: 32 additions & 0 deletions src/.deploy/temp-stand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { CREDENTIAL_KEY } from "features/auth";

const tempStandRegex = /^(github-client-47c49|dev-github-client)--pr\d+.+\.web\.app$/;

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() || !devStorageUrl) {
if(!devStorageUrl) {
console.debug(`Note that you need to provide ${STAND_URL_ENV} env to make dev stand work`)
}
return;
}
// @ts-ignore
const { default: createGuest } = await import("cross-domain-storage/guest");
const storage = createGuest(devStorageUrl);
const userCredentialRaw = await new Promise<string | undefined>((resolve, reject) =>
storage.get(CREDENTIAL_KEY, (error: any, data: string | undefined) => {
if (error) {
reject(error);
return;
}
resolve(data);
}),
);
if (userCredentialRaw) {
localStorage.setItem(CREDENTIAL_KEY, userCredentialRaw);
}
};
17 changes: 11 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ 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";

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root"),
);
function renderApp() {
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root"),
);
}

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.
Expand Down

0 comments on commit 2d4568e

Please sign in to comment.