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