refactor: 解耦側邊列表
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
import Client from "../api/Client.ts"
|
import Client from "../api/Client.ts"
|
||||||
import data from "../Data.ts"
|
import data from "../Data.ts"
|
||||||
import ChatFragment from "./chat/ChatFragment.tsx"
|
import ChatFragment from "./chat/ChatFragment.tsx"
|
||||||
import ContactsListItem from "./main/ContactsListItem.jsx"
|
|
||||||
import RecentsListItem from "./main/RecentsListItem.jsx"
|
|
||||||
import useEventListener from './useEventListener.ts'
|
import useEventListener from './useEventListener.ts'
|
||||||
import User from "../api/client_data/User.ts"
|
import User from "../api/client_data/User.ts"
|
||||||
import RecentChat from "../api/client_data/RecentChat.ts"
|
import RecentChat from "../api/client_data/RecentChat.ts"
|
||||||
@@ -17,6 +15,8 @@ import { checkApiSuccessOrSncakbar } from "./snackbar.ts"
|
|||||||
import RegisterDialog from "./dialog/RegisterDialog.tsx"
|
import RegisterDialog from "./dialog/RegisterDialog.tsx"
|
||||||
import LoginDialog from "./dialog/LoginDialog.tsx"
|
import LoginDialog from "./dialog/LoginDialog.tsx"
|
||||||
import UserProfileDialog from "./dialog/UserProfileDialog.tsx"
|
import UserProfileDialog from "./dialog/UserProfileDialog.tsx"
|
||||||
|
import ContactsList from "./main/ContactsList.tsx";
|
||||||
|
import RecentsList from "./main/RecentsList.tsx";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace React {
|
namespace React {
|
||||||
@@ -143,47 +143,15 @@ export default function App() {
|
|||||||
<div id="SideBar">
|
<div id="SideBar">
|
||||||
{
|
{
|
||||||
// 最近聊天
|
// 最近聊天
|
||||||
<mdui-list style={{
|
<RecentsList
|
||||||
overflowY: 'auto',
|
display={navigationItemSelected == "Recents"}
|
||||||
paddingRight: '10px',
|
recentsList={recentsList} />
|
||||||
display: navigationItemSelected == "Recents" ? undefined : 'none'
|
|
||||||
}}>
|
|
||||||
{
|
|
||||||
recentsList.map((v) =>
|
|
||||||
<RecentsListItem
|
|
||||||
key={v.id}
|
|
||||||
nickName={v.title}
|
|
||||||
avatar={v.avatar}
|
|
||||||
content={v.content} />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</mdui-list>
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// 联系人列表
|
// 联系人列表
|
||||||
<mdui-list style={{
|
<ContactsList
|
||||||
overflowY: 'auto',
|
display={navigationItemSelected == "Contacts"}
|
||||||
paddingRight: '10px',
|
contactsMap={contactsMap} />
|
||||||
display: navigationItemSelected == "Contacts" ? undefined : 'none'
|
|
||||||
}}>
|
|
||||||
<mdui-collapse accordion value={Object.keys(contactsMap)[0]}>
|
|
||||||
{
|
|
||||||
Object.keys(contactsMap).map((v) =>
|
|
||||||
<mdui-collapse-item key={v} value={v}>
|
|
||||||
<mdui-list-subheader slot="header">{v}</mdui-list-subheader>
|
|
||||||
{
|
|
||||||
contactsMap[v].map((v2) =>
|
|
||||||
<ContactsListItem
|
|
||||||
key={v2.id}
|
|
||||||
nickName={v2.nickname}
|
|
||||||
avatar={v2.avatar} />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</mdui-collapse-item>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</mdui-collapse>
|
|
||||||
</mdui-list>
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import Client from "../api/Client.ts"
|
import Client from "../api/Client.ts"
|
||||||
import data from "../Data.ts"
|
import data from "../Data.ts"
|
||||||
import ChatFragment from "./chat/ChatFragment.tsx"
|
|
||||||
import ContactsListItem from "./main/ContactsListItem.jsx"
|
|
||||||
import RecentsListItem from "./main/RecentsListItem.jsx"
|
|
||||||
import useEventListener from './useEventListener.ts'
|
import useEventListener from './useEventListener.ts'
|
||||||
import User from "../api/client_data/User.ts"
|
import User from "../api/client_data/User.ts"
|
||||||
import RecentChat from "../api/client_data/RecentChat.ts"
|
import RecentChat from "../api/client_data/RecentChat.ts"
|
||||||
import Avatar from "./Avatar.tsx"
|
|
||||||
|
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import { Dialog, NavigationBar, TextField } from "mdui"
|
import { Dialog, NavigationBar, TextField } from "mdui"
|
||||||
@@ -16,6 +12,8 @@ import { checkApiSuccessOrSncakbar } from "./snackbar.ts"
|
|||||||
import RegisterDialog from "./dialog/RegisterDialog.tsx"
|
import RegisterDialog from "./dialog/RegisterDialog.tsx"
|
||||||
import LoginDialog from "./dialog/LoginDialog.tsx"
|
import LoginDialog from "./dialog/LoginDialog.tsx"
|
||||||
import UserProfileDialog from "./dialog/UserProfileDialog.tsx"
|
import UserProfileDialog from "./dialog/UserProfileDialog.tsx"
|
||||||
|
import ContactsList from "./main/ContactsList.tsx"
|
||||||
|
import RecentsList from "./main/RecentsList.tsx"
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace React {
|
namespace React {
|
||||||
@@ -75,9 +73,9 @@ export default function AppMobile() {
|
|||||||
|
|
||||||
const userProfileDialogRef: React.MutableRefObject<Dialog | null> = React.useRef(null)
|
const userProfileDialogRef: React.MutableRefObject<Dialog | null> = React.useRef(null)
|
||||||
const openMyUserProfileDialogButtonRef: React.MutableRefObject<HTMLElement | null> = React.useRef(null)
|
const openMyUserProfileDialogButtonRef: React.MutableRefObject<HTMLElement | null> = React.useRef(null)
|
||||||
/* useEventListener(openMyUserProfileDialogButtonRef, 'click', (_event) => {
|
/* useEventListener(openMyUserProfileDialogButtonRef, 'click', (_event) => {
|
||||||
userProfileDialogRef.current!.open = true
|
userProfileDialogRef.current!.open = true
|
||||||
})*/
|
})*/
|
||||||
|
|
||||||
const [myUserProfileCache, setMyUserProfileCache]: [User, React.Dispatch<React.SetStateAction<User>>] = React.useState(null as unknown as User)
|
const [myUserProfileCache, setMyUserProfileCache]: [User, React.Dispatch<React.SetStateAction<User>>] = React.useState(null as unknown as User)
|
||||||
|
|
||||||
@@ -119,12 +117,12 @@ export default function AppMobile() {
|
|||||||
<UserProfileDialog
|
<UserProfileDialog
|
||||||
userProfileDialogRef={userProfileDialogRef}
|
userProfileDialogRef={userProfileDialogRef}
|
||||||
user={myUserProfileCache} />
|
user={myUserProfileCache} />
|
||||||
|
|
||||||
<mdui-navigation-bar scroll-target="#SideBar" label-visibility="selected" value="Recents" ref={navigationBarRef}>
|
<mdui-navigation-bar scroll-target="#SideBar" label-visibility="selected" value="Recents" ref={navigationBarRef}>
|
||||||
<mdui-navigation-bar-item icon="watch_later--outlined" value="Recents">最近</mdui-navigation-bar-item>
|
<mdui-navigation-bar-item icon="watch_later--outlined" value="Recents">最近</mdui-navigation-bar-item>
|
||||||
<mdui-navigation-bar-item icon="contacts--outlined" value="Contacts">聯絡人</mdui-navigation-bar-item>
|
<mdui-navigation-bar-item icon="contacts--outlined" value="Contacts">聯絡人</mdui-navigation-bar-item>
|
||||||
</mdui-navigation-bar>
|
</mdui-navigation-bar>
|
||||||
|
|
||||||
<div style={{
|
<div style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
height: 'calc(100% - 80px)',
|
height: 'calc(100% - 80px)',
|
||||||
@@ -132,51 +130,15 @@ export default function AppMobile() {
|
|||||||
}} id="SideBar">
|
}} id="SideBar">
|
||||||
{
|
{
|
||||||
// 最近聊天
|
// 最近聊天
|
||||||
<mdui-list style={{
|
<RecentsList
|
||||||
overflowY: 'auto',
|
display={navigationItemSelected == "Recents"}
|
||||||
marginLeft: '10px',
|
recentsList={recentsList} />
|
||||||
marginRight: '10px',
|
|
||||||
width: '100%',
|
|
||||||
display: navigationItemSelected == "Recents" ? undefined : 'none'
|
|
||||||
}}>
|
|
||||||
{
|
|
||||||
recentsList.map((v) =>
|
|
||||||
<RecentsListItem
|
|
||||||
key={v.id}
|
|
||||||
nickName={v.title}
|
|
||||||
avatar={v.avatar}
|
|
||||||
content={v.content} />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</mdui-list>
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// 联系人列表
|
// 联系人列表
|
||||||
<mdui-list style={{
|
<ContactsList
|
||||||
overflowY: 'auto',
|
display={navigationItemSelected == "Contacts"}
|
||||||
marginLeft: '10px',
|
contactsMap={contactsMap} />
|
||||||
marginRight: '10px',
|
|
||||||
width: '100%',
|
|
||||||
display: navigationItemSelected == "Contacts" ? undefined : 'none'
|
|
||||||
}}>
|
|
||||||
<mdui-collapse accordion value={Object.keys(contactsMap)[0]}>
|
|
||||||
{
|
|
||||||
Object.keys(contactsMap).map((v) =>
|
|
||||||
<mdui-collapse-item key={v} value={v}>
|
|
||||||
<mdui-list-subheader slot="header">{v}</mdui-list-subheader>
|
|
||||||
{
|
|
||||||
contactsMap[v].map((v2) =>
|
|
||||||
<ContactsListItem
|
|
||||||
key={v2.id}
|
|
||||||
nickName={v2.nickname}
|
|
||||||
avatar={v2.avatar} />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</mdui-collapse-item>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</mdui-collapse>
|
|
||||||
</mdui-list>
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
40
client/ui/main/ContactsList.tsx
Normal file
40
client/ui/main/ContactsList.tsx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import User from "../../api/client_data/User.ts"
|
||||||
|
import ContactsListItem from "./ContactsListItem.jsx"
|
||||||
|
|
||||||
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
|
contactsMap: { [key: string]: User[] }
|
||||||
|
display: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ContactsList({
|
||||||
|
contactsMap,
|
||||||
|
display,
|
||||||
|
...props
|
||||||
|
}: Args) {
|
||||||
|
return <mdui-list style={{
|
||||||
|
overflowY: 'auto',
|
||||||
|
marginLeft: '10px',
|
||||||
|
marginRight: '10px',
|
||||||
|
width: '100%',
|
||||||
|
display: display ? undefined : 'none'
|
||||||
|
}} {...props}>
|
||||||
|
|
||||||
|
<mdui-collapse accordion value={Object.keys(contactsMap)[0]}>
|
||||||
|
{
|
||||||
|
Object.keys(contactsMap).map((v) =>
|
||||||
|
<mdui-collapse-item key={v} value={v}>
|
||||||
|
<mdui-list-subheader slot="header">{v}</mdui-list-subheader>
|
||||||
|
{
|
||||||
|
contactsMap[v].map((v2) =>
|
||||||
|
<ContactsListItem
|
||||||
|
key={v2.id}
|
||||||
|
nickName={v2.nickname}
|
||||||
|
avatar={v2.avatar} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</mdui-collapse-item>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</mdui-collapse>
|
||||||
|
</mdui-list>
|
||||||
|
}
|
||||||
31
client/ui/main/RecentsList.tsx
Normal file
31
client/ui/main/RecentsList.tsx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import RecentChat from "../../api/client_data/RecentChat.ts"
|
||||||
|
import User from "../../api/client_data/User.ts"
|
||||||
|
import ContactsListItem from "./ContactsListItem.jsx"
|
||||||
|
import RecentsListItem from "./RecentsListItem.jsx"
|
||||||
|
|
||||||
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
|
recentsList: RecentChat[]
|
||||||
|
display: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function RecentsList({
|
||||||
|
recentsList,
|
||||||
|
display,
|
||||||
|
...props
|
||||||
|
}: Args) {
|
||||||
|
return <mdui-list style={{
|
||||||
|
overflowY: 'auto',
|
||||||
|
paddingRight: '10px',
|
||||||
|
display: display ? undefined : 'none'
|
||||||
|
}}>
|
||||||
|
{
|
||||||
|
recentsList.map((v) =>
|
||||||
|
<RecentsListItem
|
||||||
|
key={v.id}
|
||||||
|
nickName={v.title}
|
||||||
|
avatar={v.avatar}
|
||||||
|
content={v.content} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</mdui-list>
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user