Skip to content

Commit

Permalink
Refactor App.tsx; Update page field in manifest.json
Browse files Browse the repository at this point in the history
  • Loading branch information
earvinpiamonte committed Feb 7, 2021
1 parent 6fd6382 commit b582341
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
4 changes: 2 additions & 2 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
}
],
"page_action": {
"default_popup": "index.html?page=popup",
"default_popup": "index.html?page=Popup",
"default_title": "Open Jira Software Tool"
},
"options_page": "index.html?page=options",
"options_page": "index.html?page=Options",
"icons": {
"16": "images/16.png",
"32": "images/32.png",
Expand Down
29 changes: 9 additions & 20 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from "react";

import GetManifestWithChrome from "./utils/GetManifestWithChrome";

import Popup from "./pages/Popup";
import Options from "./pages/Options";
import Test from "./pages/Test";

const App = ({ page }: { page: string }) => {
const Component = React.lazy(
() => import(`./pages/${page}`).catch((err) => null) // catch but I hope I don't fall
);

const [manifest, setManifest] = React.useState();

const loadManifest = async () => {
Expand All @@ -18,22 +18,11 @@ const App = ({ page }: { page: string }) => {
loadManifest();
}, []);

// check what page is requested base on `page` props passed from `index.js`
switch (page) {
case "popup":
return <Popup manifest={manifest} />;
case "options":
return <Options manifest={manifest} />;
case "test":
return process.env.NODE_ENV === "development" ? (
<Test />
) : (
<Options manifest={manifest} />
);
// return default page - Options page
default:
return <Options manifest={manifest} />;
}
return (
<React.Suspense fallback={null}>
<Component manifest={manifest} />
</React.Suspense>
);
};

export default App;

0 comments on commit b582341

Please sign in to comment.