refactor: 抽离 openChatInfoDialog
This commit is contained in:
@@ -34,8 +34,6 @@ declare global {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const [recentsList, setRecentsList] = React.useState([] as RecentChat[])
|
|
||||||
|
|
||||||
const [navigationItemSelected, setNavigationItemSelected] = React.useState('Recents')
|
const [navigationItemSelected, setNavigationItemSelected] = React.useState('Recents')
|
||||||
|
|
||||||
const navigationRailRef = React.useRef<NavigationRail>(null)
|
const navigationRailRef = React.useRef<NavigationRail>(null)
|
||||||
@@ -57,7 +55,7 @@ export default function App() {
|
|||||||
useEventListener(openMyProfileDialogButtonRef, 'click', (_event) => {
|
useEventListener(openMyProfileDialogButtonRef, 'click', (_event) => {
|
||||||
myProfileDialogRef.current!.open = true
|
myProfileDialogRef.current!.open = true
|
||||||
})
|
})
|
||||||
|
|
||||||
const addContactDialogRef = React.useRef<Dialog>(null)
|
const addContactDialogRef = React.useRef<Dialog>(null)
|
||||||
|
|
||||||
const chatInfoDialogRef = React.useRef<Dialog>(null)
|
const chatInfoDialogRef = React.useRef<Dialog>(null)
|
||||||
@@ -91,6 +89,11 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function openChatInfoDialog(chat: Chat) {
|
||||||
|
setChatInfo(chat)
|
||||||
|
chatInfoDialogRef.current!.open = true
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@@ -123,7 +126,7 @@ export default function App() {
|
|||||||
setIsShowChatFragment(true)
|
setIsShowChatFragment(true)
|
||||||
}}
|
}}
|
||||||
chat={chatInfo} />
|
chat={chatInfo} />
|
||||||
|
|
||||||
<AddContactDialog
|
<AddContactDialog
|
||||||
addContactDialogRef={addContactDialogRef} />
|
addContactDialogRef={addContactDialogRef} />
|
||||||
|
|
||||||
@@ -149,16 +152,13 @@ export default function App() {
|
|||||||
setIsShowChatFragment(true)
|
setIsShowChatFragment(true)
|
||||||
}}
|
}}
|
||||||
display={navigationItemSelected == "Recents"}
|
display={navigationItemSelected == "Recents"}
|
||||||
currentChatId={currentChatId}
|
currentChatId={currentChatId} />
|
||||||
recentsList={recentsList}
|
|
||||||
setRecentsList={setRecentsList} />
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// 對話列表
|
// 對話列表
|
||||||
<ContactsList
|
<ContactsList
|
||||||
setChatInfo={setChatInfo}
|
openChatInfoDialog={openChatInfoDialog}
|
||||||
addContactDialogRef={addContactDialogRef as any}
|
addContactDialogRef={addContactDialogRef as any}
|
||||||
chatInfoDialogRef={chatInfoDialogRef as any}
|
|
||||||
display={navigationItemSelected == "Contacts"} />
|
display={navigationItemSelected == "Contacts"} />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@@ -181,6 +181,7 @@ export default function App() {
|
|||||||
{
|
{
|
||||||
isShowChatFragment && <ChatFragment
|
isShowChatFragment && <ChatFragment
|
||||||
target={currentChatId}
|
target={currentChatId}
|
||||||
|
openChatInfoDialog={openChatInfoDialog}
|
||||||
key={currentChatId} />
|
key={currentChatId} />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ declare global {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function AppMobile() {
|
export default function AppMobile() {
|
||||||
const [recentsList, setRecentsList] = React.useState([] as RecentChat[])
|
|
||||||
|
|
||||||
const [navigationItemSelected, setNavigationItemSelected] = React.useState('Recents')
|
const [navigationItemSelected, setNavigationItemSelected] = React.useState('Recents')
|
||||||
|
|
||||||
const navigationBarRef = React.useRef<NavigationBar>(null)
|
const navigationBarRef = React.useRef<NavigationBar>(null)
|
||||||
@@ -56,7 +54,7 @@ export default function AppMobile() {
|
|||||||
useEventListener(openMyProfileDialogButtonRef, 'click', (_event) => {
|
useEventListener(openMyProfileDialogButtonRef, 'click', (_event) => {
|
||||||
myProfileDialogRef.current!.open = true
|
myProfileDialogRef.current!.open = true
|
||||||
})
|
})
|
||||||
|
|
||||||
const addContactDialogRef = React.useRef<Dialog>(null)
|
const addContactDialogRef = React.useRef<Dialog>(null)
|
||||||
|
|
||||||
const chatInfoDialogRef = React.useRef<Dialog>(null)
|
const chatInfoDialogRef = React.useRef<Dialog>(null)
|
||||||
@@ -93,6 +91,11 @@ export default function AppMobile() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function openChatInfoDialog(chat: Chat) {
|
||||||
|
setChatInfo(chat)
|
||||||
|
chatInfoDialogRef.current!.open = true
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@@ -113,6 +116,7 @@ export default function AppMobile() {
|
|||||||
showReturnButton={true}
|
showReturnButton={true}
|
||||||
onReturnButtonClicked={() => setIsShowChatFragment(false)}
|
onReturnButtonClicked={() => setIsShowChatFragment(false)}
|
||||||
key={currentChatId}
|
key={currentChatId}
|
||||||
|
openChatInfoDialog={openChatInfoDialog}
|
||||||
target={currentChatId} />
|
target={currentChatId} />
|
||||||
</div>
|
</div>
|
||||||
</mdui-dialog>
|
</mdui-dialog>
|
||||||
@@ -142,7 +146,7 @@ export default function AppMobile() {
|
|||||||
setIsShowChatFragment(true)
|
setIsShowChatFragment(true)
|
||||||
}}
|
}}
|
||||||
chat={chatInfo} />
|
chat={chatInfo} />
|
||||||
|
|
||||||
<AddContactDialog
|
<AddContactDialog
|
||||||
addContactDialogRef={addContactDialogRef} />
|
addContactDialogRef={addContactDialogRef} />
|
||||||
|
|
||||||
@@ -183,16 +187,13 @@ export default function AppMobile() {
|
|||||||
setIsShowChatFragment(true)
|
setIsShowChatFragment(true)
|
||||||
}}
|
}}
|
||||||
display={navigationItemSelected == "Recents"}
|
display={navigationItemSelected == "Recents"}
|
||||||
currentChatId={currentChatId}
|
currentChatId={currentChatId} />
|
||||||
recentsList={recentsList}
|
|
||||||
setRecentsList={setRecentsList} />
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// 對話列表
|
// 對話列表
|
||||||
<ContactsList
|
<ContactsList
|
||||||
setChatInfo={setChatInfo}
|
openChatInfoDialog={openChatInfoDialog}
|
||||||
addContactDialogRef={addContactDialogRef as any}
|
addContactDialogRef={addContactDialogRef as any}
|
||||||
chatInfoDialogRef={chatInfoDialogRef as any}
|
|
||||||
display={navigationItemSelected == "Contacts"} />
|
display={navigationItemSelected == "Contacts"} />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,15 +11,13 @@ import EventBus from "../../EventBus.ts"
|
|||||||
|
|
||||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
display: boolean
|
display: boolean
|
||||||
chatInfoDialogRef: React.MutableRefObject<Dialog>
|
openChatInfoDialog: (chat: Chat) => void
|
||||||
addContactDialogRef: React.MutableRefObject<Dialog>
|
addContactDialogRef: React.MutableRefObject<Dialog>
|
||||||
setChatInfo: React.Dispatch<React.SetStateAction<Chat>>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ContactsList({
|
export default function ContactsList({
|
||||||
display,
|
display,
|
||||||
setChatInfo,
|
openChatInfoDialog,
|
||||||
chatInfoDialogRef,
|
|
||||||
addContactDialogRef,
|
addContactDialogRef,
|
||||||
...props
|
...props
|
||||||
}: Args) {
|
}: Args) {
|
||||||
@@ -84,8 +82,7 @@ export default function ContactsList({
|
|||||||
/*if (isMultiSelecting)
|
/*if (isMultiSelecting)
|
||||||
self.active = !self.active
|
self.active = !self.active
|
||||||
else*/
|
else*/
|
||||||
setChatInfo(v)
|
openChatInfoDialog(v)
|
||||||
chatInfoDialogRef.current!.open = true
|
|
||||||
}}
|
}}
|
||||||
key={v.id}
|
key={v.id}
|
||||||
contact={v} />
|
contact={v} />
|
||||||
|
|||||||
Reference in New Issue
Block a user