feat: 在对话信息页面收藏/取消收藏
This commit is contained in:
@@ -77,6 +77,8 @@ export default function App() {
|
||||
|
||||
const [currentChatId, setCurrentChatId] = React.useState('')
|
||||
|
||||
const [sharedFavouriteChats, setSharedFavouriteChats] = React.useState<Chat[]>([])
|
||||
|
||||
useAsyncEffect(async () => {
|
||||
const split = Split(['#SideBar', '#ChatFragment'], {
|
||||
sizes: data.split_sizes ? data.split_sizes : [25, 75],
|
||||
@@ -176,6 +178,7 @@ export default function App() {
|
||||
chatInfoDialogRef={chatInfoDialogRef as any}
|
||||
openChatFragment={openChatFragment}
|
||||
openUserInfoDialog={openUserInfoDialog}
|
||||
sharedFavouriteChats={sharedFavouriteChats}
|
||||
chat={chatInfo} />
|
||||
|
||||
<MyProfileDialog
|
||||
@@ -218,6 +221,7 @@ export default function App() {
|
||||
// 對話列表
|
||||
<ContactsList
|
||||
openChatInfoDialog={openChatInfoDialog}
|
||||
setSharedFavouriteChats={setSharedFavouriteChats}
|
||||
addContactDialogRef={addContactDialogRef as any}
|
||||
createGroupDialogRef={createGroupDialogRef as any}
|
||||
display={navigationItemSelected == "Contacts"} />
|
||||
|
||||
@@ -74,6 +74,8 @@ export default function AppMobile() {
|
||||
|
||||
const [currentChatId, setCurrentChatId] = React.useState('')
|
||||
|
||||
const [sharedFavouriteChats, setSharedFavouriteChats] = React.useState<Chat[]>([])
|
||||
|
||||
const chatFragmentDialogRef = React.useRef<Dialog>(null)
|
||||
React.useEffect(() => {
|
||||
const shadow = chatFragmentDialogRef.current!.shadowRoot as ShadowRoot
|
||||
@@ -162,6 +164,7 @@ export default function AppMobile() {
|
||||
<ChatInfoDialog
|
||||
chatInfoDialogRef={chatInfoDialogRef as any}
|
||||
openUserInfoDialog={openUserInfoDialog}
|
||||
sharedFavouriteChats={sharedFavouriteChats}
|
||||
openChatFragment={(id) => {
|
||||
setCurrentChatId(id)
|
||||
setIsShowChatFragment(true)
|
||||
@@ -226,6 +229,7 @@ export default function AppMobile() {
|
||||
// 對話列表
|
||||
<ContactsList
|
||||
openChatInfoDialog={openChatInfoDialog}
|
||||
setSharedFavouriteChats={setSharedFavouriteChats}
|
||||
addContactDialogRef={addContactDialogRef as any}
|
||||
createGroupDialogRef={createGroupDialogRef as any}
|
||||
display={navigationItemSelected == "Contacts"} />
|
||||
|
||||
@@ -9,17 +9,19 @@ import { checkApiSuccessOrSncakbar } from "../snackbar.ts"
|
||||
import User from "../../api/client_data/User.ts"
|
||||
import getUrlForFileByHash from "../../getUrlForFileByHash.ts"
|
||||
import openImageViewer from "../openImageViewer.ts"
|
||||
import EventBus from "../../EventBus.ts"
|
||||
|
||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||
chat: Chat
|
||||
openChatFragment: (id: string) => void
|
||||
chatInfoDialogRef: React.MutableRefObject<Dialog>
|
||||
openUserInfoDialog: (user: User | string) => void
|
||||
sharedFavouriteChats: Chat[]
|
||||
}
|
||||
|
||||
export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragment, openUserInfoDialog }: Args) {
|
||||
export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragment, openUserInfoDialog, sharedFavouriteChats }: Args) {
|
||||
const [chatInfo, setChatInfo] = React.useState(null as unknown as Chat)
|
||||
const isMySelf = Client.myUserProfile?.id == chatInfo?.user_a_id && Client.myUserProfile?.id == chatInfo?.user_b_id
|
||||
const [favourited, setIsFavourited] = React.useState(false)
|
||||
|
||||
useAsyncEffect(async () => {
|
||||
if (chat == null) return
|
||||
@@ -29,8 +31,11 @@ export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragme
|
||||
})
|
||||
if (re.code != 200)
|
||||
return checkApiSuccessOrSncakbar(re, '获取对话信息失败')
|
||||
setChatInfo(re.data!.chat_info as Chat)
|
||||
})
|
||||
|
||||
const info = re.data as Chat
|
||||
setChatInfo(info)
|
||||
setIsFavourited(sharedFavouriteChats.indexOf(info) != -1)
|
||||
}, [chat, sharedFavouriteChats])
|
||||
const avatarUrl = getUrlForFileByHash(chat?.avatar_file_hash as string)
|
||||
|
||||
return (
|
||||
@@ -66,6 +71,17 @@ export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragme
|
||||
openUserInfoDialog(re.data!.user_id as string)
|
||||
}}>用户详情</mdui-list-item>
|
||||
}
|
||||
<mdui-list-item icon={favourited ? "favorite_border" : "favorite"} rounded onClick={async () => {
|
||||
const re = await Client.invoke(favourited ? "User.removeContacts" : "User.addContacts", {
|
||||
token: data.access_token,
|
||||
targets: [
|
||||
chat.id
|
||||
],
|
||||
})
|
||||
if (re.code != 200)
|
||||
checkApiSuccessOrSncakbar(re, favourited ? "取消收藏失败" : "收藏失败")
|
||||
EventBus.emit('ContactsList.updateContacts')
|
||||
}}>{favourited ? '取消收藏' : '收藏对话'}</mdui-list-item>
|
||||
<mdui-list-item icon="chat" rounded onClick={() => {
|
||||
chatInfoDialogRef.current!.open = false
|
||||
openChatFragment(chat.id)
|
||||
|
||||
@@ -13,6 +13,7 @@ interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||
openChatInfoDialog: (chat: Chat) => void
|
||||
addContactDialogRef: React.MutableRefObject<Dialog>
|
||||
createGroupDialogRef: React.MutableRefObject<Dialog>
|
||||
setSharedFavouriteChats: React.Dispatch<React.SetStateAction<Chat[]>>
|
||||
}
|
||||
|
||||
export default function ContactsList({
|
||||
@@ -20,6 +21,7 @@ export default function ContactsList({
|
||||
openChatInfoDialog,
|
||||
addContactDialogRef,
|
||||
createGroupDialogRef,
|
||||
setSharedFavouriteChats,
|
||||
...props
|
||||
}: Args) {
|
||||
const searchRef = React.useRef<HTMLElement>(null)
|
||||
@@ -40,7 +42,9 @@ export default function ContactsList({
|
||||
if (re.code != 200)
|
||||
return checkApiSuccessOrSncakbar(re, "获取所有对话列表失败")
|
||||
|
||||
setContactsList(re.data!.contacts_list as Chat[])
|
||||
const ls = re.data!.contacts_list as Chat[]
|
||||
setContactsList(ls)
|
||||
setSharedFavouriteChats(ls)
|
||||
}
|
||||
updateContacts()
|
||||
EventBus.on('ContactsList.updateContacts', () => updateContacts())
|
||||
|
||||
Reference in New Issue
Block a user