准备重新编写 ChatInfoDialog
This commit is contained in:
@@ -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