generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #665 from hackforla/google-analytics-2
Google analytics 2
- Loading branch information
Showing
15 changed files
with
175 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { BrowserRouter as Router } from "react-router-dom"; | ||
import { UserContext } from "./components/user-context"; | ||
import App from "./App"; | ||
import NavConfirmModal from "./components/NavConfirmModal"; | ||
|
||
const AppWrapper = () => { | ||
const [account, setAccount] = useState({}); | ||
const [confirmTransition, setConfirmTransition] = useState(null); | ||
const [hasConfirmedTransition, setHasConfirmedTransition] = useState(true); | ||
const [isOpenNavConfirmModal, setIsOpenNavConfirmModal] = useState(false); | ||
|
||
const setLoggedInAccount = loggedInUser => { | ||
setAccount(loggedInUser); | ||
localStorage.setItem("currentUser", JSON.stringify(loggedInUser)); | ||
}; | ||
|
||
useEffect(() => { | ||
const currentUser = localStorage.getItem("currentUser"); | ||
if (currentUser) { | ||
try { | ||
const parsedAccount = JSON.parse(currentUser); | ||
setAccount(parsedAccount); | ||
} catch (err) { | ||
// TODO: replace with production error logging. | ||
console.error( | ||
"Unable to parse current user from local storage.", | ||
currentUser | ||
); | ||
} | ||
} else { | ||
setLoggedInAccount({}); | ||
} | ||
}, []); | ||
|
||
const getUserConfirmation = (_message, defaultConfirmCallback) => { | ||
setHasConfirmedTransition(false); | ||
setConfirmTransition(() => ({ | ||
defaultConfirmCallback: defaultConfirmCallback, | ||
setHasConfirmedTransition: setHasConfirmedTransition | ||
})); | ||
setIsOpenNavConfirmModal(!isOpenNavConfirmModal); | ||
}; | ||
|
||
return ( | ||
<React.Fragment> | ||
<UserContext.Provider value={account}> | ||
<Router getUserConfirmation={getUserConfirmation}> | ||
<NavConfirmModal | ||
confirmTransition={confirmTransition} | ||
isOpenNavConfirmModal={isOpenNavConfirmModal} | ||
setIsOpenNavConfirmModal={setIsOpenNavConfirmModal} | ||
/> | ||
<App | ||
account={account} | ||
setLoggedInAccount={setLoggedInAccount} | ||
hasConfirmedTransition={hasConfirmedTransition} | ||
/> | ||
</Router> | ||
</UserContext.Provider> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
export default AppWrapper; | ||
import React, { useState, useEffect } from "react"; | ||
import { BrowserRouter as Router } from "react-router-dom"; | ||
import { UserContext } from "./components/user-context"; | ||
import App from "./App"; | ||
import NavConfirmModal from "./components/NavConfirmModal"; | ||
|
||
const AppWrapper = () => { | ||
const [account, setAccount] = useState({}); | ||
const [confirmTransition, setConfirmTransition] = useState(null); | ||
const [hasConfirmedTransition, setHasConfirmedTransition] = useState(true); | ||
const [isOpenNavConfirmModal, setIsOpenNavConfirmModal] = useState(false); | ||
|
||
const setLoggedInAccount = loggedInUser => { | ||
setAccount(loggedInUser); | ||
localStorage.setItem("currentUser", JSON.stringify(loggedInUser)); | ||
}; | ||
|
||
useEffect(() => { | ||
const currentUser = localStorage.getItem("currentUser"); | ||
if (currentUser) { | ||
try { | ||
const parsedAccount = JSON.parse(currentUser); | ||
setAccount(parsedAccount); | ||
} catch (err) { | ||
// TODO: replace with production error logging. | ||
console.error( | ||
"Unable to parse current user from local storage.", | ||
currentUser | ||
); | ||
} | ||
} else { | ||
setLoggedInAccount({}); | ||
} | ||
}, []); | ||
|
||
const getUserConfirmation = (_message, defaultConfirmCallback) => { | ||
setHasConfirmedTransition(false); | ||
setConfirmTransition(() => ({ | ||
defaultConfirmCallback: defaultConfirmCallback, | ||
setHasConfirmedTransition: setHasConfirmedTransition | ||
})); | ||
setIsOpenNavConfirmModal(!isOpenNavConfirmModal); | ||
}; | ||
|
||
return ( | ||
<React.Fragment> | ||
<UserContext.Provider value={account}> | ||
<Router getUserConfirmation={getUserConfirmation}> | ||
<NavConfirmModal | ||
confirmTransition={confirmTransition} | ||
isOpenNavConfirmModal={isOpenNavConfirmModal} | ||
setIsOpenNavConfirmModal={setIsOpenNavConfirmModal} | ||
/> | ||
<App | ||
account={account} | ||
setLoggedInAccount={setLoggedInAccount} | ||
hasConfirmedTransition={hasConfirmedTransition} | ||
/> | ||
</Router> | ||
</UserContext.Provider> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
export default AppWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.