@@ -9,7 +9,9 @@ import {TimerBlocker} from "./Timer";
99import {
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" ;
1315import { timerInit } from "../logic/timerInit" ;
1416import { timerReducer } from "../logic/timerReducer" ;
1517
@@ -31,11 +33,45 @@ function parseURLQuery() {
3133}
3234
3335export 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
0 commit comments