Skip to content

Commit f93d7af

Browse files
authored
Merge pull request #286 from zhangxichang/branch-1
refactor: 简化 Toaster API 并实现好友请求处理
2 parents 8157a0e + 9d7746d commit f93d7af

15 files changed

Lines changed: 90 additions & 107 deletions

File tree

schema.prisma

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ model user {
1818
}
1919

2020
model friend {
21-
id String @id
22-
user_id String
23-
name String
24-
avatar Bytes?
25-
bio String
21+
id String @id
22+
owner_id String
23+
name String
24+
avatar Bytes?
25+
bio String
2626
}
2727

28-
model message {
29-
id Int @id @default(autoincrement())
30-
sender_id String
31-
timestamp DateTime @default(now())
28+
model chat_message {
29+
timestamp DateTime @id @default(now())
30+
owner_id String
31+
chat_user_id String
3232
content String
3333
}

src/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (import.meta.env.TAURI_ENV_PLATFORM !== undefined) {
2020
log_error(error);
2121
void createTauRPCProxy().log.error(error.message);
2222
};
23-
window.onunhandledrejection = (e) => {
23+
onunhandledrejection = (e) => {
2424
e.preventDefault();
2525
console.error(e.reason);
2626
};

src/components/modal/add_friend.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,14 @@ export default function AddFriend() {
7676
home_store.endpoint.request_friend(v().id),
7777
)();
7878
if (err) {
79-
shell_store.toaster.popup("error", err.message);
79+
shell_store.toaster.popup(err.message);
8080
} else {
8181
// TODO 处理好友添加
8282
if (agree) {
83-
shell_store.toaster.popup(
84-
"success",
85-
"对方同意好友请求",
86-
);
83+
shell_store.toaster.popup("对方同意好友请求");
8784
console.info(v());
8885
} else {
89-
shell_store.toaster.popup(
90-
"error",
91-
"对方拒绝好友请求",
92-
);
86+
shell_store.toaster.popup("对方拒绝好友请求");
9387
}
9488
}
9589
set_send_friend_request_button_disabled(false);

src/components/modal/setting.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ export default function Setting() {
88
<button
99
class="btn"
1010
onClick={() => {
11-
shell_store.toaster.popup("success", "你好,世界");
11+
const close = shell_store.toaster.popup("你好,世界");
12+
setTimeout(() => {
13+
close();
14+
}, 3000);
1215
}}
1316
>
1417
测试按钮

src/components/ui/chat_bar.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ export default function ChatBar(props: { chat_user: User }) {
1212
const shell_store = use_context(ShellContext);
1313
const main_store = use_context(MainContext);
1414
const [user] = shell_store.user;
15-
const messages = createAsync(
16-
async () =>
17-
await main_store.sqlite.query<Message>(
18-
QueryBuilder.selectFrom("message")
19-
.select(["sender_id", "timestamp", "content"])
20-
.where("sender_id", "=", props.chat_user.id)
21-
.compile(),
22-
),
23-
);
15+
const messages = createAsync(async () => {
16+
const u = user();
17+
if (!u) throw new Error("用户不存在");
18+
return await main_store.sqlite.query<Message>(
19+
QueryBuilder.selectFrom("chat_message")
20+
.select(["chat_user_id", "timestamp", "content"])
21+
.where("owner_id", "=", u.id)
22+
.where("chat_user_id", "=", props.chat_user.id)
23+
.compile(),
24+
);
25+
});
2426
let message_list_ref: HTMLDivElement | undefined;
2527
const message_list_virtualizer = createVirtualizer({
2628
getScrollElement: () => message_list_ref ?? null,

src/components/ui/friend_list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function FriendList(props: {
2222
await main_store.sqlite.query<User>(
2323
QueryBuilder.selectFrom("friend")
2424
.select(["id", "name", "avatar", "bio"])
25-
.where("user_id", "=", params.user_id)
25+
.where("owner_id", "=", params.user_id)
2626
.compile(),
2727
),
2828
);

src/lib/endpoint/native.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class EndpointModuleImpl implements EndpointModule {
2525
}
2626

2727
export class EndpointImpl implements Endpoint {
28-
private handle: bigint;
28+
private handle;
2929

3030
private constructor(handle: bigint) {
3131
this.handle = handle;

src/lib/endpoint/web.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class EndpointModuleImpl implements EndpointModule {
2828
}
2929

3030
export class EndpointImpl implements Endpoint {
31-
private endpoint: WasmEndpoint;
31+
private endpoint;
3232

3333
private constructor(endpoint: WasmEndpoint) {
3434
this.endpoint = endpoint;

src/lib/sqlite/native.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export class SQLiteModuleImpl implements SQLiteModule {
1212
}
1313

1414
export class SQLiteImpl implements SQLite {
15-
private handle: bigint;
16-
private on_updates: ((event: SQLiteUpdateEvent) => void)[];
15+
private handle;
16+
private on_updates;
1717

1818
private constructor(
1919
handle: bigint,

src/lib/sqlite/web.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export class SQLiteModuleImpl implements SQLiteModule {
3030
}
3131

3232
export class SQLiteImpl implements SQLite {
33-
private api: Remote<SQLiteWorker>;
34-
private id: number;
35-
private on_updates: ((event: SQLiteUpdateEvent) => void)[];
33+
private api;
34+
private id;
35+
private on_updates;
3636

3737
private constructor(
3838
api: Remote<SQLiteWorker>,

0 commit comments

Comments
 (0)