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

fix: adding the loading state for the Join btn on the landing page. #315

Merged
merged 1 commit into from
Oct 10, 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
5 changes: 0 additions & 5 deletions demo/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { ConfigProvider } from "antd"
import { StoreProvider } from "@/store";
import type { Metadata, Viewport } from "next";

import './global.css'


export const metadata: Metadata = {
title: "TEN Agent",
description: "The World's First Multimodal AI Agent with the OpenAI Realtime API (Beta)",
Expand All @@ -23,9 +21,6 @@ export const viewport: Viewport = {
viewportFit: "cover",
}




export default function RootLayout({
children,
}: Readonly<{
Expand Down
8 changes: 4 additions & 4 deletions demo/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export default function Login() {

return (
<main className={styles.login}>
<div className={styles.starts}></div>
<div className={styles.starts2}></div>
<div className={styles.starts3}></div>
<LoginCard></LoginCard>
<div className={styles.starts} />
<div className={styles.starts2} />
<div className={styles.starts3} />
<LoginCard />
</main>
);
}
31 changes: 31 additions & 0 deletions demo/src/components/loginCard/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@
font-weight: 500;
line-height: 24px;
}

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

&.btnDisabled {
background-color: #808080; // Gray color
cursor: not-allowed;
opacity: 0.7; // Optional: reduces opacity to further indicate disabled state
}
}

Expand All @@ -109,4 +119,25 @@
}

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

.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; }
}
}
59 changes: 45 additions & 14 deletions demo/src/components/loginCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
"use client"

import packageData from "../../../package.json"
import type React from 'react';
import { useRouter } from 'next/navigation'
import { message } from "antd"
import { useState } from "react"
import { GithubIcon, LogoIcon } from "../icons"
import { useState, useEffect } from "react"
import { GITHUB_URL, getRandomUserId, useAppDispatch, getRandomChannel } from "@/common"
import { setOptions } from "@/store/reducers/global"
import styles from "./index.module.scss"

import { GithubIcon } from "../icons"
import packageData from "../../../package.json"

const { version } = packageData

const LoginCard = () => {
const dispatch = useAppDispatch()
const router = useRouter()
const [userName, setUserName] = useState("")
const [isLoadingSuccess, setIsLoadingSuccess] = useState(false);

const onClickGithub = () => {
if (typeof window !== "undefined") {
window.open(GITHUB_URL, "_blank")
}
}

const onUserNameChange = (e: any) => {
const onUserNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
let value = e.target.value
value = value.replace(/\s/g, "");
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) {
message.error("please input user name")
message.error("please enter a user name")
return
}
const userId = getRandomUserId()
Expand All @@ -45,11 +58,20 @@ const LoginCard = () => {
router.push("/home")
}


return <div className={styles.card}>
<section className={styles.top}>
<span className={styles.github} onClick={onClickGithub}>
<GithubIcon></GithubIcon>
<span
className={styles.github}
onClick={onClickGithub}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
onClickGithub();
}
}}
role="button"
tabIndex={0}
>
<GithubIcon />
<span className={styles.text}>GitHub</span>
</span>
</section>
Expand All @@ -59,19 +81,28 @@ const LoginCard = () => {
<span className={styles.text}>The World's First Multimodal AI Agent with the OpenAI Realtime API (Beta)</span>
</div>
<div className={styles.section}>
<input placeholder="User Name" value={userName} onChange={onUserNameChange} ></input>
<input placeholder="User Name" value={userName} onChange={onUserNameChange} />
</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}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
onClickJoin();
}
}}
role="button"
tabIndex={0}
>
<div className={styles.btnText}>
{isLoadingSuccess ? "Join" : <div><span>Loading</span><span className={styles.dotting} /></div>}
</div>
</div>
</div>
<div className={styles.version}>Version {version}</div>
</section >
</div >


return
}

export default LoginCard
4 changes: 2 additions & 2 deletions demo/src/platform/pc/description/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ const Description = () => {
return <div className={styles.description}>
<span className={styles.title}>Description</span>
<span className={styles.text}>The World's First Multimodal AI Agent with the OpenAI Realtime API (Beta)</span>
<span className={`${styles.btnConnect} ${agentConnected ? styles.disconnect : ''}`} onClick={onClickConnect}>
<span className={`${styles.btnConnect} ${agentConnected ? styles.disconnect : ''}`} onClick={onClickConnect} onKeyUp={onClickConnect} onKeyDown={onClickConnect} onKeyPress={onClickConnect}>
<span className={`${styles.btnText} ${agentConnected ? styles.disconnect : ''}`}>
{!agentConnected ? "Connect" : "Disconnect"}
{loading ? <LoadingOutlined className={styles.loading}></LoadingOutlined> : null}
{loading ? <LoadingOutlined className={styles.loading} /> : null}
</span>
</span>
</div>
Expand Down