-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. GetNickname only befor priminum 2. redirect add loading 3. remove google anylitic
- Loading branch information
Showing
9 changed files
with
349 additions
and
285 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,65 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import Device from 'device.js'; | ||
import Device from "device.js"; | ||
import { useRouter } from "next/router"; | ||
import { useEffect } from "react"; | ||
import { useEffect, useState } from "react"; | ||
import { Dimmer, Loader, Progress } from "semantic-ui-react"; | ||
import { useContextWrapLoginUser } from "../lib/wallet/hooks"; | ||
|
||
const NO_CHECK_USER = [ | ||
'/files/share', | ||
'/files/receive' | ||
] | ||
function RedirectLoading(p: { children?: React.ReactNode }) { | ||
// const [percent, setPercent] = useState(0); | ||
// useEffect(() => { | ||
// const timer = setInterval(() => { | ||
// setPercent((p) => { | ||
// p >= 80 && clearInterval(timer); | ||
// return p + 1; | ||
// }); | ||
// }, 200); | ||
// return () => clearInterval(timer); | ||
// }, []); | ||
return ( | ||
<> | ||
{p.children} | ||
<Dimmer active inverted style={{ position: "fixed", left: 0, top: 0, width: "100vw", height: "100vh" }}> | ||
<Loader active inverted size="large" /> | ||
</Dimmer> | ||
{/* <Progress | ||
success | ||
percent={percent} | ||
indicating | ||
size="tiny" | ||
style={{ position: "fixed", zIndex: 1000, top: 0, left: 0, width: "100%" }} | ||
/> */} | ||
</> | ||
); | ||
} | ||
|
||
const NO_CHECK_USER = ["/files/share", "/files/receive"]; | ||
export default function Redirect(props: { children: any }) { | ||
const wUser = useContextWrapLoginUser(); | ||
const router = useRouter(); | ||
useEffect(() => { | ||
const isMobile = new Device().mobile | ||
if (router.pathname !== '/mobile' && isMobile) { | ||
router.replace('/mobile') | ||
} else if (router.pathname === '/mobile' && !isMobile) { | ||
router.replace('/') | ||
const isMobile = new Device().mobile; | ||
if (router.pathname !== "/mobile" && isMobile) { | ||
router.replace("/mobile"); | ||
} else if (router.pathname === "/mobile" && !isMobile) { | ||
router.replace("/"); | ||
} | ||
}, [router]) | ||
}, [router]); | ||
|
||
// no support mobile | ||
if (router.pathname === '/mobile') return props.children; | ||
if (router.pathname === "/mobile") return props.children; | ||
// no check user | ||
if (NO_CHECK_USER.includes(router.pathname)) return props.children; | ||
|
||
// check user | ||
if ((!wUser.account || !wUser.authBasic) && (router.pathname !== '' && router.pathname !== '/')) { | ||
router.replace('/') | ||
return null | ||
if ((!wUser.account || !wUser.authBasic) && router.pathname !== "" && router.pathname !== "/") { | ||
router.replace("/"); | ||
return <RedirectLoading>{props.children}</RedirectLoading>; | ||
} | ||
if (wUser.account && wUser.authBasic && (router.pathname === '' || router.pathname === '/')) { | ||
router.replace(`/home/${window.location.search}`) | ||
return null | ||
|
||
if (wUser.account && wUser.authBasic && (router.pathname === "" || router.pathname === "/")) { | ||
router.replace(`/home/${window.location.search}`); | ||
return <RedirectLoading>{props.children}</RedirectLoading>; | ||
} | ||
return props.children; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import _ from "lodash"; | ||
import { useEffect } from "react"; | ||
import { getMemberByAccount, getNickNameByAccount } from "./http/share_earn"; | ||
import { useContextWrapLoginUser } from "./wallet/hooks"; | ||
|
||
export function useLoadNickname() { | ||
const wUser = useContextWrapLoginUser(); | ||
const { account, wallet } = wUser; | ||
useEffect(() => { | ||
if (account && wallet === "crust") { | ||
wUser.setIsLoadingNickname(true); | ||
getMemberByAccount(account) | ||
.then(wUser.setMember) | ||
.catch(console.error) | ||
.then(() => getNickNameByAccount(account)) | ||
.then((name) => wUser.setNickName(name)) | ||
.catch(console.error) | ||
.then(() => wUser.setIsLoadingNickname(false)); | ||
} | ||
wUser.setMember(undefined); | ||
wUser.setNickName(""); | ||
}, [account, wallet]); | ||
} |
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