Compare commits
3 Commits
03f6f2743f
...
fc3df592bc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc3df592bc | ||
|
|
5ce42bf651 | ||
|
|
6a8acd4717 |
@@ -21,6 +21,7 @@ const _data_cached = JSON.parse(_dec)
|
|||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
data: {
|
data: {
|
||||||
|
split_sizes: number[];
|
||||||
apply(): void
|
apply(): void
|
||||||
access_token?: string
|
access_token?: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,16 +38,15 @@ export default function App() {
|
|||||||
content: "成步堂君, 我又坐牢了("
|
content: "成步堂君, 我又坐牢了("
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '0',
|
id: '1',
|
||||||
avatar: "https://www.court-records.net/mugshot/aa6-004-maya.png",
|
avatar: "https://www.court-records.net/mugshot/aa6-004-maya.png",
|
||||||
title: "Maya Fey",
|
title: "Maya Fey",
|
||||||
content: "我是绫里真宵, 是一名灵媒师~"
|
content: "我是绫里真宵, 是一名灵媒师~"
|
||||||
},
|
},
|
||||||
] as RecentChat[])
|
] as RecentChat[])
|
||||||
const [contactsMap, setContactsMap] = React.useState({
|
const [contactsList, setContactsList] = React.useState([
|
||||||
所有: [
|
|
||||||
{
|
{
|
||||||
id: '0',
|
id: '1',
|
||||||
avatar: "https://www.court-records.net/mugshot/aa6-004-maya.png",
|
avatar: "https://www.court-records.net/mugshot/aa6-004-maya.png",
|
||||||
nickname: "麻油衣酱",
|
nickname: "麻油衣酱",
|
||||||
},
|
},
|
||||||
@@ -56,26 +55,26 @@ export default function App() {
|
|||||||
avatar: "https://www.court-records.net/mugshot/aa6-004-maya.png",
|
avatar: "https://www.court-records.net/mugshot/aa6-004-maya.png",
|
||||||
nickname: "Maya Fey",
|
nickname: "Maya Fey",
|
||||||
},
|
},
|
||||||
],
|
] as User[])
|
||||||
} as unknown as { [key: string]: User[] })
|
|
||||||
const [navigationItemSelected, setNavigationItemSelected] = React.useState('Recents')
|
const [navigationItemSelected, setNavigationItemSelected] = React.useState('Recents')
|
||||||
|
|
||||||
const navigationRailRef: React.MutableRefObject<NavigationRail | null> = React.useRef(null)
|
const navigationRailRef = React.useRef<NavigationRail>(null)
|
||||||
useEventListener(navigationRailRef, 'change', (event) => {
|
useEventListener(navigationRailRef, 'change', (event) => {
|
||||||
setNavigationItemSelected((event.target as HTMLElement as NavigationRail).value as string)
|
setNavigationItemSelected((event.target as HTMLElement as NavigationRail).value as string)
|
||||||
})
|
})
|
||||||
|
|
||||||
const loginDialogRef: React.MutableRefObject<Dialog | null> = React.useRef(null)
|
const loginDialogRef = React.useRef<Dialog>(null)
|
||||||
const loginInputAccountRef: React.MutableRefObject<TextField | null> = React.useRef(null)
|
const loginInputAccountRef = React.useRef<TextField>(null)
|
||||||
const loginInputPasswordRef: React.MutableRefObject<TextField | null> = React.useRef(null)
|
const loginInputPasswordRef = React.useRef<TextField>(null)
|
||||||
|
|
||||||
const registerDialogRef: React.MutableRefObject<Dialog | null> = React.useRef(null)
|
const registerDialogRef = React.useRef<Dialog>(null)
|
||||||
const registerInputUserNameRef: React.MutableRefObject<TextField | null> = React.useRef(null)
|
const registerInputUserNameRef = React.useRef<TextField>(null)
|
||||||
const registerInputNickNameRef: React.MutableRefObject<TextField | null> = React.useRef(null)
|
const registerInputNickNameRef = React.useRef<TextField>(null)
|
||||||
const registerInputPasswordRef: React.MutableRefObject<TextField | null> = React.useRef(null)
|
const registerInputPasswordRef = React.useRef<TextField>(null)
|
||||||
|
|
||||||
const userProfileDialogRef: React.MutableRefObject<Dialog | null> = React.useRef(null)
|
const userProfileDialogRef = React.useRef<Dialog>(null)
|
||||||
const openMyUserProfileDialogButtonRef: React.MutableRefObject<HTMLElement | null> = React.useRef(null)
|
const openMyUserProfileDialogButtonRef = React.useRef<HTMLElement>(null)
|
||||||
useEventListener(openMyUserProfileDialogButtonRef, 'click', (_event) => {
|
useEventListener(openMyUserProfileDialogButtonRef, 'click', (_event) => {
|
||||||
userProfileDialogRef.current!.open = true
|
userProfileDialogRef.current!.open = true
|
||||||
})
|
})
|
||||||
@@ -88,10 +87,14 @@ export default function App() {
|
|||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
; (async () => {
|
; (async () => {
|
||||||
Split(['#SideBar', '#ChatFragment'], {
|
const split = Split(['#SideBar', '#ChatFragment'], {
|
||||||
sizes: [25, 75],
|
sizes: data.split_sizes ? data.split_sizes : [25, 75],
|
||||||
minSize: [200, 400],
|
minSize: [200, 400],
|
||||||
gutterSize: 2,
|
gutterSize: 2,
|
||||||
|
onDragEnd: function () {
|
||||||
|
data.split_sizes = split.getSizes()
|
||||||
|
data.apply()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Client.connect()
|
Client.connect()
|
||||||
@@ -136,8 +139,8 @@ export default function App() {
|
|||||||
<Avatar src={myUserProfileCache?.avatar} text={myUserProfileCache?.nickname} avatarRef={openMyUserProfileDialogButtonRef} />
|
<Avatar src={myUserProfileCache?.avatar} text={myUserProfileCache?.nickname} avatarRef={openMyUserProfileDialogButtonRef} />
|
||||||
</mdui-button-icon>
|
</mdui-button-icon>
|
||||||
|
|
||||||
<mdui-navigation-rail-item icon="watch_later--outlined" value="Recents"></mdui-navigation-rail-item>
|
<mdui-navigation-rail-item icon="watch_later--outlined" active-icon="watch_later--filled" value="Recents"></mdui-navigation-rail-item>
|
||||||
<mdui-navigation-rail-item icon="contacts--outlined" value="Contacts"></mdui-navigation-rail-item>
|
<mdui-navigation-rail-item icon="contacts--outlined" active-icon="contacts--filled" value="Contacts"></mdui-navigation-rail-item>
|
||||||
|
|
||||||
<mdui-button-icon icon="settings" slot="bottom"></mdui-button-icon>
|
<mdui-button-icon icon="settings" slot="bottom"></mdui-button-icon>
|
||||||
</mdui-navigation-rail>
|
</mdui-navigation-rail>
|
||||||
@@ -153,7 +156,8 @@ export default function App() {
|
|||||||
|
|
||||||
}}
|
}}
|
||||||
display={navigationItemSelected == "Recents"}
|
display={navigationItemSelected == "Recents"}
|
||||||
recentsList={recentsList} />
|
recentsList={recentsList}
|
||||||
|
setRecentsList={setRecentsList} />
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// 联系人列表
|
// 联系人列表
|
||||||
@@ -162,7 +166,8 @@ export default function App() {
|
|||||||
setIsShowChatFragment(true)
|
setIsShowChatFragment(true)
|
||||||
}}
|
}}
|
||||||
display={navigationItemSelected == "Contacts"}
|
display={navigationItemSelected == "Contacts"}
|
||||||
contactsMap={contactsMap} />
|
contactsList={contactsList}
|
||||||
|
setContactsList={setContactsList} />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
|
import React from "react"
|
||||||
import User from "../../api/client_data/User.ts"
|
import User from "../../api/client_data/User.ts"
|
||||||
import ContactsListItem from "./ContactsListItem.tsx"
|
import ContactsListItem from "./ContactsListItem.tsx"
|
||||||
|
|
||||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
contactsMap: { [key: string]: User[] }
|
contactsList: User[]
|
||||||
|
setContactsList: React.Dispatch<React.SetStateAction<User[]>>
|
||||||
display: boolean
|
display: boolean
|
||||||
openChatFragment: (id: string) => void
|
openChatFragment: (id: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ContactsList({
|
export default function ContactsList({
|
||||||
contactsMap,
|
contactsList,
|
||||||
|
setContactsList,
|
||||||
display,
|
display,
|
||||||
openChatFragment,
|
openChatFragment,
|
||||||
...props
|
...props
|
||||||
@@ -17,28 +20,19 @@ export default function ContactsList({
|
|||||||
overflowY: 'auto',
|
overflowY: 'auto',
|
||||||
paddingLeft: '10px',
|
paddingLeft: '10px',
|
||||||
paddingRight: '10px',
|
paddingRight: '10px',
|
||||||
display: display ? undefined : 'none'
|
display: display ? undefined : 'none',
|
||||||
|
height: '100%',
|
||||||
}} {...props}>
|
}} {...props}>
|
||||||
|
|
||||||
<mdui-collapse accordion value={Object.keys(contactsMap)[0]}>
|
|
||||||
<mdui-list-item rounded style={{
|
<mdui-list-item rounded style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
}} icon="person_add">添加聯絡人</mdui-list-item>
|
}} icon="person_add">添加聯絡人</mdui-list-item>
|
||||||
{
|
{
|
||||||
Object.keys(contactsMap).map((v) =>
|
contactsList.map((v2) =>
|
||||||
<mdui-collapse-item key={v} value={v}>
|
|
||||||
<mdui-list-subheader slot="header">{v}</mdui-list-subheader>
|
|
||||||
{
|
|
||||||
contactsMap[v].map((v2) =>
|
|
||||||
<ContactsListItem
|
<ContactsListItem
|
||||||
openChatFragment={openChatFragment}
|
openChatFragment={openChatFragment}
|
||||||
key={v2.id}
|
key={v2.id}
|
||||||
contact={v2} />
|
contact={v2} />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</mdui-collapse-item>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</mdui-collapse>
|
|
||||||
</mdui-list>
|
</mdui-list>
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import User from "../../api/client_data/User.ts"
|
import User from "../../api/client_data/User.ts"
|
||||||
import Avatar from "../Avatar.tsx"
|
import Avatar from "../Avatar.tsx"
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
contact: User
|
contact: User
|
||||||
@@ -8,8 +9,10 @@ interface Args extends React.HTMLAttributes<HTMLElement> {
|
|||||||
|
|
||||||
export default function ContactsListItem({ contact, openChatFragment }: Args) {
|
export default function ContactsListItem({ contact, openChatFragment }: Args) {
|
||||||
const { id, nickname, avatar } = contact
|
const { id, nickname, avatar } = contact
|
||||||
|
const ref = React.useRef<HTMLElement>(null)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<mdui-list-item rounded style={{
|
<mdui-list-item ref={ref} rounded style={{
|
||||||
marginTop: '3px',
|
marginTop: '3px',
|
||||||
marginBottom: '3px',
|
marginBottom: '3px',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ import RecentsListItem from "./RecentsListItem.tsx"
|
|||||||
|
|
||||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
recentsList: RecentChat[]
|
recentsList: RecentChat[]
|
||||||
|
setRecentsList: React.Dispatch<React.SetStateAction<RecentChat[]>>
|
||||||
display: boolean
|
display: boolean
|
||||||
openChatFragment: (id: string) => void
|
openChatFragment: (id: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function RecentsList({
|
export default function RecentsList({
|
||||||
recentsList,
|
recentsList,
|
||||||
|
setRecentsList,
|
||||||
display,
|
display,
|
||||||
openChatFragment,
|
openChatFragment,
|
||||||
...props
|
...props
|
||||||
@@ -16,7 +18,8 @@ export default function RecentsList({
|
|||||||
return <mdui-list style={{
|
return <mdui-list style={{
|
||||||
overflowY: 'auto',
|
overflowY: 'auto',
|
||||||
paddingRight: '10px',
|
paddingRight: '10px',
|
||||||
display: display ? undefined : 'none'
|
display: display ? undefined : 'none',
|
||||||
|
height: '100%',
|
||||||
}} {...props}>
|
}} {...props}>
|
||||||
{
|
{
|
||||||
recentsList.map((v) =>
|
recentsList.map((v) =>
|
||||||
|
|||||||
@@ -93,6 +93,6 @@ export function checkApiSuccessOrSncakbar(re: ApiCallbackMessage, msg_ahead: str
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function snackbar(opinions: SnackbarOptions) {
|
export function snackbar(opinions: SnackbarOptions) {
|
||||||
opinions.autoCloseDelay == null && (opinions.autoCloseDelay = 2500)
|
opinions.autoCloseDelay == null && (opinions.autoCloseDelay = 3500)
|
||||||
return mduiSnackbar(opinions)
|
return mduiSnackbar(opinions)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export default class User {
|
|||||||
username,
|
username,
|
||||||
nickname,
|
nickname,
|
||||||
avatar_file_hash,
|
avatar_file_hash,
|
||||||
contact_groups,
|
contacts_list,
|
||||||
settings
|
settings
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`).run(
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`).run(
|
||||||
crypto.randomUUID(),
|
crypto.randomUUID(),
|
||||||
@@ -71,17 +71,12 @@ export default class User {
|
|||||||
userName,
|
userName,
|
||||||
nickName,
|
nickName,
|
||||||
null,
|
null,
|
||||||
'{}',
|
'[]',
|
||||||
"{}"
|
"{}"
|
||||||
).lastInsertRowid
|
).lastInsertRowid
|
||||||
)[0]
|
)[0]
|
||||||
)
|
)
|
||||||
avatar && user.setAvatar(avatar)
|
avatar && user.setAvatar(avatar)
|
||||||
user.setContactGroups({
|
|
||||||
默認: [
|
|
||||||
user.bean.id
|
|
||||||
]
|
|
||||||
})
|
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,21 +115,19 @@ export default class User {
|
|||||||
setUserName(userName: string) {
|
setUserName(userName: string) {
|
||||||
this.setAttr("username", userName)
|
this.setAttr("username", userName)
|
||||||
}
|
}
|
||||||
getContactGroups() {
|
addContact(userId) {
|
||||||
|
|
||||||
|
}
|
||||||
|
getContactsList() {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(this.bean.contact_groups)
|
return JSON.parse(this.bean.contacts_list)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(chalk.yellow(`警告: 聯絡人組解析失敗: ${(e as Error).message}`))
|
console.log(chalk.yellow(`警告: 聯絡人組解析失敗: ${(e as Error).message}`))
|
||||||
return {
|
return [
|
||||||
默認: [
|
|
||||||
this.bean.id
|
this.bean.id
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
setContactGroups(contactGroups: { [key: string]: string[] }) {
|
|
||||||
this.setAttr("contact_groups", JSON.stringify(contactGroups))
|
|
||||||
}
|
|
||||||
getNickName(): string {
|
getNickName(): string {
|
||||||
return this.bean.nickname
|
return this.bean.nickname
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export default class UserBean {
|
|||||||
declare registered_time: number
|
declare registered_time: number
|
||||||
declare nickname: string
|
declare nickname: string
|
||||||
declare avatar_file_hash?: string
|
declare avatar_file_hash?: string
|
||||||
declare contact_groups: string
|
declare contacts_list: string
|
||||||
declare settings: string
|
declare settings: string
|
||||||
|
|
||||||
[key: string]: unknown
|
[key: string]: unknown
|
||||||
|
|||||||
Reference in New Issue
Block a user