Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve first time loading experience, only enable Join button until it's fully functional #299

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions playground/src/components/loginCard/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
line-height: 24px;
}
}

.btnLoadingBg {
background: var(--primary-500-base, #434343);
}
}

.section+.section {
Expand All @@ -111,3 +115,21 @@

}
}


.dotting { display: inline-block; width: 10px; min-height: 2px;
padding-right: 2px;
border-left: 2px solid currentColor; border-right: 2px solid currentColor;
background-color: currentColor; background-clip: content-box;
box-sizing: border-box;
-webkit-animation: dot 1.5s infinite step-start both;
animation: dot 1.5s infinite step-start both;
}
.dotting::before { content: ''; }
:root .dotting { margin-left: 2px; padding-left: 2px; }

@keyframes dot {
25% { border-color: transparent; background-color: transparent; }
50% { border-right-color: transparent; background-color: transparent; }
75% { border-right-color: transparent; }
}
20 changes: 17 additions & 3 deletions playground/src/components/loginCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import packageData from "../../../package.json"
import { useRouter } from 'next/navigation'
import { message } from "antd"
import { useState } from "react"
import { useState, useEffect } from "react"
import { GithubIcon, LogoIcon } from "../icons"
import { GITHUB_URL, getRandomUserId, useAppDispatch, getRandomChannel } from "@/common"
import { setOptions } from "@/store/reducers/global"
Expand All @@ -16,6 +16,7 @@ const LoginCard = () => {
const dispatch = useAppDispatch()
const router = useRouter()
const [userName, setUserName] = useState("")
const [isLoadingSuccess, setIsLoadingSuccess] = useState(false);

const onClickGithub = () => {
if (typeof window !== "undefined") {
Expand All @@ -29,7 +30,18 @@ const LoginCard = () => {
setUserName(value)
}

useEffect(() => {
const onPageLoad = () => {
setIsLoadingSuccess(true);
};

if (document.readyState === 'complete') {
onPageLoad();
} else {
window.addEventListener('load', onPageLoad, false);
return () => window.removeEventListener('load', onPageLoad);
}
}, []);

const onClickJoin = () => {
if (!userName) {
Expand Down Expand Up @@ -63,8 +75,10 @@ const LoginCard = () => {
<input placeholder="User Name" value={userName} onChange={onUserNameChange} ></input>
</div>
<div className={styles.section}>
<div className={styles.btn} onClick={onClickJoin}>
<span className={styles.btnText}>Join</span>
<div className={`${styles.btn} ${!isLoadingSuccess && styles.btnLoadingBg}`} onClick={onClickJoin}>
<div className={styles.btnText}>
{isLoadingSuccess ? "Join" : <div><span>Loading</span><span className={styles.dotting}></span></div>}
</div>
</div>
</div>
<div className={styles.version}>Version {version}</div>
Expand Down