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(demo): remove login page #397

Merged
merged 2 commits into from
Nov 11, 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
51 changes: 0 additions & 51 deletions demo/src/app/home/page.tsx

This file was deleted.

57 changes: 48 additions & 9 deletions demo/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
import LoginCard from "@/components/Card/Login"
import styles from "./index.module.css"
"use client"

import { useAppSelector, EMobileActiveTab } from "@/common"
import dynamic from "next/dynamic"

import Header from "@/components/Layout/Header"
import Action from "@/components/Layout/Action"
// import RTCCard from "@/components/Dynamic/RTCCard"
// import ChatCard from "@/components/Chat/ChatCard"
import AuthInitializer from "@/components/authInitializer"
import { cn } from "@/lib/utils"

const DynamicRTCCard = dynamic(() => import("@/components/Dynamic/RTCCard"), {
ssr: false,
})

const DynamicChatCard = dynamic(() => import("@/components/Chat/ChatCard"), {
ssr: false,
})

export default function Home() {
const mobileActiveTab = useAppSelector(
(state) => state.global.mobileActiveTab,
)

export default function Login() {
return (
<main className={styles.login}>
<div className={styles.starts} />
<div className={styles.starts2} />
<div className={styles.starts3} />
<LoginCard />
</main>
<AuthInitializer>
<div className="relative mx-auto flex h-full min-h-screen flex-col md:h-screen">
<Header className="h-[60px]" />
<Action className="h-[48px]" />
<div className="mx-2 mb-2 flex h-full max-h-[calc(100vh-108px-24px)] flex-col md:flex-row md:gap-2">
<DynamicRTCCard
className={cn(
"m-0 w-full rounded-b-lg bg-[#181a1d] md:w-[480px] md:rounded-lg",
{
["hidden md:block"]: mobileActiveTab === EMobileActiveTab.CHAT,
},
)}
/>
<DynamicChatCard
className={cn(
"m-0 w-full rounded-b-lg bg-[#181a1d] md:rounded-lg",
{
["hidden md:block"]: mobileActiveTab === EMobileActiveTab.AGENT,
},
)}
/>
</div>
</div>
</AuthInitializer>
)
}
24 changes: 18 additions & 6 deletions demo/src/components/authInitializer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
"use client"

import { ReactNode, useEffect } from "react"
import { useAppDispatch, getOptionsFromLocal } from "@/common"
import {
useAppDispatch,
getOptionsFromLocal,
getRandomUserId,
getRandomChannel,
genRandomString,
} from "@/common"
import { setOptions, reset, setAgentSettings } from "@/store/reducers/global"

interface AuthInitializerProps {
children: ReactNode;
children: ReactNode
}

const AuthInitializer = (props: AuthInitializerProps) => {
const { children } = props;
const { children } = props
const dispatch = useAppDispatch()

useEffect(() => {
if (typeof window !== "undefined") {
const data = getOptionsFromLocal()
if (data) {
if (data && data?.options?.channel) {
dispatch(reset())
dispatch(setOptions(data.options))
dispatch(setAgentSettings(data.settings))
} else {
const newOptions = {
userName: genRandomString(8),
channel: getRandomChannel(),
userId: getRandomUserId(),
}
dispatch(setOptions(newOptions))
}
}
}, [dispatch])

return children
}


export default AuthInitializer;
export default AuthInitializer