Skip to content

Commit 4bb1ea4

Browse files
committed
use shared install components
1 parent 4ff6d79 commit 4bb1ea4

File tree

5 files changed

+66
-69
lines changed

5 files changed

+66
-69
lines changed

src/components/App.js

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {TimerBlocker} from "./Timer";
99
import {
1010
handleAppInstalled,
1111
handleBeforeInstallPrompt,
12-
} from "../logic/handleInstall";
12+
} from "@skedwards88/shared-components/src/logic/handleInstall";
13+
import InstallOverview from "@skedwards88/shared-components/src/components/InstallOverview";
14+
import PWAInstall from "@skedwards88/shared-components/src/components/PWAInstall";
1315
import {timerInit} from "../logic/timerInit";
1416
import {timerReducer} from "../logic/timerReducer";
1517

@@ -31,11 +33,45 @@ function parseURLQuery() {
3133
}
3234

3335
export default function App() {
36+
// *****
37+
// Install handling setup
38+
// *****
39+
// Set up states that will be used by the handleAppInstalled and handleBeforeInstallPrompt listeners
40+
const [installPromptEvent, setInstallPromptEvent] = React.useState();
41+
const [showInstallButton, setShowInstallButton] = React.useState(true);
42+
43+
React.useEffect(() => {
44+
// Need to store the function in a variable so that
45+
// the add and remove actions can reference the same function
46+
const listener = (event) =>
47+
handleBeforeInstallPrompt(
48+
event,
49+
setInstallPromptEvent,
50+
setShowInstallButton,
51+
);
52+
53+
window.addEventListener("beforeinstallprompt", listener);
54+
55+
return () => window.removeEventListener("beforeinstallprompt", listener);
56+
}, []);
57+
58+
React.useEffect(() => {
59+
// Need to store the function in a variable so that
60+
// the add and remove actions can reference the same function
61+
const listener = () =>
62+
handleAppInstalled(setInstallPromptEvent, setShowInstallButton);
63+
64+
window.addEventListener("appinstalled", listener);
65+
66+
return () => window.removeEventListener("appinstalled", listener);
67+
}, []);
68+
// *****
69+
// End install handling setup
70+
// *****
71+
3472
const [seed, gridSize, minWordLength, easyMode] = parseURLQuery();
3573

3674
const [display, setDisplay] = React.useState("pause");
37-
const [installPromptEvent, setInstallPromptEvent] = React.useState();
38-
const [showInstallButton, setShowInstallButton] = React.useState(true);
3975

4076
const [gameState, dispatchGameState] = React.useReducer(
4177
gameReducer,
@@ -90,26 +126,6 @@ export default function App() {
90126
document.removeEventListener("visibilitychange", handleVisibilityChange);
91127
});
92128

93-
React.useEffect(() => {
94-
const listener = (event) =>
95-
handleBeforeInstallPrompt(
96-
event,
97-
setInstallPromptEvent,
98-
setShowInstallButton,
99-
);
100-
101-
window.addEventListener("beforeinstallprompt", listener);
102-
return () => window.removeEventListener("beforeinstallprompt", listener);
103-
}, []);
104-
105-
React.useEffect(() => {
106-
const listener = () =>
107-
handleAppInstalled(setInstallPromptEvent, setShowInstallButton);
108-
109-
window.addEventListener("appinstalled", listener);
110-
return () => window.removeEventListener("appinstalled", listener);
111-
}, []);
112-
113129
switch (display) {
114130
case "settings":
115131
return (
@@ -139,6 +155,29 @@ export default function App() {
139155
case "info":
140156
return <Rules timerDispatch={timerDispatch} setDisplay={setDisplay} />;
141157

158+
case "installOverview":
159+
return (
160+
<InstallOverview
161+
setDisplay={setDisplay}
162+
setInstallPromptEvent={setInstallPromptEvent}
163+
showInstallButton={showInstallButton}
164+
installPromptEvent={installPromptEvent}
165+
googleAppLink={
166+
"https://play.google.com/store/apps/details?id=gribbles.io.github.skedwards88.twa&hl=en_US"
167+
}
168+
></InstallOverview>
169+
);
170+
171+
case "pwaInstall":
172+
return (
173+
<PWAInstall
174+
setDisplay={setDisplay}
175+
googleAppLink={
176+
"https://play.google.com/store/apps/details?id=gribbles.io.github.skedwards88.twa&hl=en_US"
177+
}
178+
></PWAInstall>
179+
);
180+
142181
case "game":
143182
return (
144183
<Game
@@ -147,9 +186,6 @@ export default function App() {
147186
timerState={timerState}
148187
timerDispatch={timerDispatch}
149188
setDisplay={setDisplay}
150-
setInstallPromptEvent={setInstallPromptEvent}
151-
showInstallButton={showInstallButton}
152-
installPromptEvent={installPromptEvent}
153189
></Game>
154190
);
155191

src/components/ControlBar.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import React from "react";
2-
import {handleInstall} from "../logic/handleInstall";
32
import {handleShare} from "./Share";
3+
import {isRunningStandalone} from "@skedwards88/shared-components/src/logic/isRunningStandalone";
44

55
export default function ControlBar({
66
gameState,
77
dispatchGameState,
88
setDisplay,
9-
setInstallPromptEvent,
10-
showInstallButton,
11-
installPromptEvent,
129
timerState,
1310
timerDispatch,
1411
}) {
@@ -74,12 +71,10 @@ export default function ControlBar({
7471
<></>
7572
)}
7673

77-
{showInstallButton && installPromptEvent ? (
74+
{!isRunningStandalone() ? (
7875
<button
7976
id="installButton"
80-
onClick={() =>
81-
handleInstall(installPromptEvent, setInstallPromptEvent)
82-
}
77+
onClick={() => setDisplay("installOverview")}
8378
></button>
8479
) : (
8580
<></>

src/components/Game.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ export default function Game({
1212
timerState,
1313
timerDispatch,
1414
setDisplay,
15-
setInstallPromptEvent,
16-
showInstallButton,
17-
installPromptEvent,
1815
}) {
1916
return (
2017
<div
@@ -32,9 +29,6 @@ export default function Game({
3229
gameState={gameState}
3330
dispatchGameState={dispatchGameState}
3431
setDisplay={setDisplay}
35-
setInstallPromptEvent={setInstallPromptEvent}
36-
showInstallButton={showInstallButton}
37-
installPromptEvent={installPromptEvent}
3832
timerState={timerState}
3933
timerDispatch={timerDispatch}
4034
></ControlBar>

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from "react";
33
import App from "./components/App";
44
import "./App.css";
55
import "@skedwards88/shared-components/src/styles/MoreGames.css";
6+
import "@skedwards88/shared-components/src/styles/Install.css";
67

78
if (process.env.NODE_ENV !== "development" && "serviceWorker" in navigator) {
89
const path =

src/logic/handleInstall.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)