Compare commits
4 Commits
20986af1ba
...
28215fc1f8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28215fc1f8 | ||
|
|
de028556af | ||
|
|
1a8df07c3b | ||
|
|
991a8a729d |
@@ -3,7 +3,7 @@ import useEventListener from "../utils/useEventListener.ts"
|
||||
import AvatarMySelf from "./AvatarMySelf.tsx"
|
||||
import MainSharedContext from './MainSharedContext.ts'
|
||||
import * as React from 'react'
|
||||
import { BrowserRouter, Link, Outlet, Route, Routes } from "react-router"
|
||||
import { BrowserRouter, Link, Outlet, Route, Routes, useNavigate } from "react-router"
|
||||
import LoginDialog from "./main-page/LoginDialog.tsx"
|
||||
import useAsyncEffect from "../utils/useAsyncEffect.ts"
|
||||
import performAuth from "../performAuth.ts"
|
||||
@@ -11,7 +11,7 @@ import { CallbackError, Chat, UserMySelf } from "lingchair-client-protocol"
|
||||
import showCircleProgressDialog from "./showCircleProgressDialog.ts"
|
||||
import RegisterDialog from "./main-page/RegisterDialog.tsx"
|
||||
import sleep from "../utils/sleep.ts"
|
||||
import { $, NavigationDrawer } from "mdui"
|
||||
import { $, Dialog, NavigationDrawer } from "mdui"
|
||||
import getClient from "../getClient.ts"
|
||||
import showSnackbar from "../utils/showSnackbar.ts"
|
||||
import AllChatsList from "./main-page/AllChatsList.tsx"
|
||||
@@ -20,6 +20,23 @@ import AddFavourtieChatDialog from "./main-page/AddFavourtieChatDialog.tsx"
|
||||
import RecentChatsList from "./main-page/RecentChatsList.tsx"
|
||||
import ChatInfoDialog from "./routers/ChatInfoDialog.tsx"
|
||||
|
||||
function Test() {
|
||||
const nav = useNavigate()
|
||||
const dialogRef = React.useRef<Dialog>()
|
||||
useAsyncEffect(async () => {
|
||||
await sleep(10)
|
||||
dialogRef.current!.open = true
|
||||
dialogRef.current!.addEventListener('overlay-click', () => {
|
||||
dialogRef.current!.open = false
|
||||
})
|
||||
dialogRef.current!.addEventListener('closed', async () => {
|
||||
await sleep(100)
|
||||
nav(-1)
|
||||
})
|
||||
}, [])
|
||||
return <mdui-dialog ref={dialogRef}></mdui-dialog>
|
||||
}
|
||||
|
||||
export default function Main() {
|
||||
const [myProfileCache, setMyProfileCache] = React.useState<UserMySelf>()
|
||||
|
||||
@@ -69,7 +86,6 @@ export default function Main() {
|
||||
setCurrentSelectedChatId,
|
||||
|
||||
myProfileCache,
|
||||
|
||||
}
|
||||
|
||||
useAsyncEffect(async () => {
|
||||
@@ -95,16 +111,9 @@ export default function Main() {
|
||||
waitingForAuth.open = false
|
||||
})
|
||||
|
||||
const subRoutes = <>
|
||||
<Route path="/info">
|
||||
<Route path="chat" element={<ChatInfoDialog />} />
|
||||
<Route path="user" element={<ChatInfoDialog />} />
|
||||
</Route>
|
||||
</>
|
||||
|
||||
return (
|
||||
<MainSharedContext.Provider value={sharedContext}>
|
||||
<BrowserRouter>
|
||||
<BrowserRouter>
|
||||
<MainSharedContext.Provider value={sharedContext}>
|
||||
<Routes>
|
||||
<Route path="/" element={(
|
||||
<div style={{
|
||||
@@ -222,10 +231,13 @@ export default function Main() {
|
||||
}
|
||||
</div>
|
||||
)}>
|
||||
{subRoutes}
|
||||
<Route path="info">
|
||||
<Route path="chat" element={<Test />} />
|
||||
<Route path="user" element={<ChatInfoDialog />} />
|
||||
</Route>
|
||||
</Route>
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
</MainSharedContext.Provider>
|
||||
</MainSharedContext.Provider>
|
||||
</BrowserRouter>
|
||||
)
|
||||
}
|
||||
@@ -9,12 +9,15 @@ type Shared = {
|
||||
}>
|
||||
favouriteChats: Chat[]
|
||||
setFavouriteChats: React.Dispatch<React.SetStateAction<Chat[]>>
|
||||
|
||||
setShowLoginDialog: React.Dispatch<React.SetStateAction<boolean>>
|
||||
setShowRegisterDialog: React.Dispatch<React.SetStateAction<boolean>>
|
||||
setShowAddFavourtieChatDialog: React.Dispatch<React.SetStateAction<boolean>>
|
||||
setCurrentSelectedChatId: React.Dispatch<React.SetStateAction<string>>
|
||||
myProfileCache?: UserMySelf
|
||||
|
||||
currentSelectedChatId: string
|
||||
setCurrentSelectedChatId: React.Dispatch<React.SetStateAction<string>>
|
||||
|
||||
myProfileCache?: UserMySelf
|
||||
}
|
||||
const MainSharedContext = createContext({} as Shared)
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ export default function AllChatsList({ ...props }: React.HTMLAttributes<HTMLElem
|
||||
const shared = useContextSelector(MainSharedContext, (context: Shared) => ({
|
||||
myProfileCache: context.myProfileCache,
|
||||
functions_lazy: context.functions_lazy,
|
||||
currentSelectedChatId: context.currentSelectedChatId,
|
||||
}))
|
||||
|
||||
const searchRef = React.useRef<HTMLElement>(null)
|
||||
@@ -68,7 +69,7 @@ export default function AllChatsList({ ...props }: React.HTMLAttributes<HTMLElem
|
||||
chat.getId().includes(searchText)
|
||||
).map((v) =>
|
||||
<AllChatsListItem
|
||||
active={isMobileUI() ? false : currentChatId == v.getId()}
|
||||
active={isMobileUI() ? false : shared.currentSelectedChatId == v.getId()}
|
||||
key={v.getId()}
|
||||
onClick={() => {
|
||||
openChatInfoDialog(v)
|
||||
|
||||
@@ -14,9 +14,9 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes<HT
|
||||
const shared = useContextSelector(MainSharedContext, (context: Shared) => ({
|
||||
myProfileCache: context.myProfileCache,
|
||||
setShowAddFavourtieChatDialog: context.setShowAddFavourtieChatDialog,
|
||||
functions_lazy: context.functions_lazy,
|
||||
favouriteChats: context.favouriteChats,
|
||||
currentSelectedChatId: context.currentSelectedChatId,
|
||||
values_lazy: context.values_lazy,
|
||||
functions_lazy: context.functions_lazy,
|
||||
}))
|
||||
|
||||
const searchRef = React.useRef<HTMLElement>(null)
|
||||
@@ -34,7 +34,7 @@ export default function FavouriteChatsList({ ...props }: React.HTMLAttributes<HT
|
||||
try {
|
||||
const ls = await shared.myProfileCache!.getMyFavouriteChatsOrThrow()
|
||||
setFavouriteChatsList(ls)
|
||||
shared.favourite_chats
|
||||
shared.favouriteChats
|
||||
} catch (e) {
|
||||
if (e instanceof CallbackError)
|
||||
if (e.code != 401 && e.code != 400)
|
||||
|
||||
@@ -20,11 +20,12 @@ export default function ChatInfoDialog({ ...props }: React.HTMLAttributes<HTMLEl
|
||||
const [userId, setUserId] = React.useState<string>()
|
||||
|
||||
const [searchParams] = useSearchParams()
|
||||
let currentLocation = useLocation()
|
||||
let pathName = useLocation().pathname
|
||||
const navigate = useNavigate()
|
||||
function back() {
|
||||
navigate(-1)
|
||||
navigate('/')
|
||||
}
|
||||
|
||||
const dialogRef = React.useRef<Dialog>()
|
||||
useEventListener(dialogRef, 'overlay-click', () => back())
|
||||
const id = searchParams.get('id')
|
||||
@@ -35,27 +36,19 @@ export default function ChatInfoDialog({ ...props }: React.HTMLAttributes<HTMLEl
|
||||
}, [chat, shared])
|
||||
|
||||
React.useEffect(() => {
|
||||
console.log(currentLocation)
|
||||
}, [currentLocation])
|
||||
console.log("挂载喵!", pathName)
|
||||
return () => console.log("被抛弃了喵!", pathName)
|
||||
}, [pathName])
|
||||
|
||||
const isUser = pathName.startsWith('/info/user')
|
||||
useAsyncEffect(async () => {
|
||||
console.log(id, currentLocation.pathname)
|
||||
console.log(id, pathName)
|
||||
try {
|
||||
if (!currentLocation.pathname.startsWith('/info/')) {
|
||||
dialogRef.current!.open = false
|
||||
return
|
||||
}
|
||||
|
||||
if (id == null) {
|
||||
dialogRef.current!.open = false
|
||||
return back()
|
||||
}
|
||||
|
||||
if (currentLocation.pathname.startsWith('/info/user')) {
|
||||
setChat(await Chat.getOrCreatePrivateChatOrThrow(getClient(), id))
|
||||
setUserId(id)
|
||||
if (isUser) {
|
||||
setChat(await Chat.getOrCreatePrivateChatOrThrow(getClient(), id!))
|
||||
setUserId(id!)
|
||||
} else
|
||||
setChat(await Chat.getByIdOrThrow(getClient(), id))
|
||||
setChat(await Chat.getByIdOrThrow(getClient(), id!))
|
||||
dialogRef.current!.open = true
|
||||
} catch (e) {
|
||||
if (e instanceof CallbackError)
|
||||
@@ -65,10 +58,7 @@ export default function ChatInfoDialog({ ...props }: React.HTMLAttributes<HTMLEl
|
||||
console.log(e)
|
||||
back()
|
||||
}
|
||||
}, [id, currentLocation])
|
||||
|
||||
if (!currentLocation.pathname.startsWith('/info/'))
|
||||
return null
|
||||
}, [id, isUser])
|
||||
|
||||
const avatarUrl = getClient().getUrlForFileByHash(chat?.getAvatarFileHash())!
|
||||
|
||||
@@ -141,4 +131,3 @@ export default function ChatInfoDialog({ ...props }: React.HTMLAttributes<HTMLEl
|
||||
</mdui-dialog>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user