-
-
-
-
-
-
+
+
+
\ No newline at end of file
diff --git a/src/routes/searchChannel.svelte b/src/routes/searchChannel.svelte
index a9fb59b..a154226 100644
--- a/src/routes/searchChannel.svelte
+++ b/src/routes/searchChannel.svelte
@@ -56,8 +56,7 @@
{#each searchResults as channel}
{channel.channelName}
-
+
{/each}
diff --git a/src/utils/api/index.js b/src/utils/api/index.js
index d8e7e7b..099b31c 100644
--- a/src/utils/api/index.js
+++ b/src/utils/api/index.js
@@ -1,2 +1,2 @@
-export const PocketBase_URL = "http://10.112.209.162:8090/_/";
+export const PocketBase_URL = "http://10.112.209.162:8090";
//export const PocketBase_URL='http://127.0.0.1:8090'; //test用
From 0a855c0e4e7c6c1192928a1e9a704d7166e079fd Mon Sep 17 00:00:00 2001
From: 0214 <3614157673@qq.com>
Date: Mon, 29 Jan 2024 00:28:21 +0800
Subject: [PATCH 04/14] feat: refine createchannel
---
src/routes/createChannel.svelte | 117 ++++++++++++++++++--------------
src/routes/searchChannel.svelte | 3 +-
2 files changed, 67 insertions(+), 53 deletions(-)
diff --git a/src/routes/createChannel.svelte b/src/routes/createChannel.svelte
index fcf308f..a5ed57b 100644
--- a/src/routes/createChannel.svelte
+++ b/src/routes/createChannel.svelte
@@ -9,13 +9,17 @@
let isLoading = false; // 新增:用于跟踪提交状态
async function handleCreate() {
- isLoading = true;
+ isLoading = true;
// 检查频道名是否已存在
- const existingChannels = await pb.collection("channels").getFullList({filter: `channelName = "${channelName}"`});
+ const existingChannels = await pb
+ .collection("channels")
+ .getFullList({ filter: `channelName = "${channelName}"` });
if (existingChannels.length > 0) {
- alert("A channel with this name already exists. Please choose a different name.");
- isLoading = false;
+ alert(
+ "A channel with this name already exists. Please choose a different name.",
+ );
+ isLoading = false;
return;
}
@@ -27,11 +31,11 @@
try {
const createdChannel = await pb.collection("channels").create(data);
alert("Channel created successfully");
- isLoading = false;
+ isLoading = false;
push("/main");
} catch (error) {
alert("ERROR: " + error.message);
- isLoading = false;
+ isLoading = false;
}
}
@@ -40,10 +44,19 @@
\ No newline at end of file
+ .btn-submit:hover {
+ background-color: #0056b3;
+ }
+
diff --git a/src/routes/searchChannel.svelte b/src/routes/searchChannel.svelte
index a154226..a9fb59b 100644
--- a/src/routes/searchChannel.svelte
+++ b/src/routes/searchChannel.svelte
@@ -56,7 +56,8 @@
{#each searchResults as channel}
{channel.channelName}
-
+
{/each}
From 01a00b28db64db093065ee04c8bbaa89ae889aa1 Mon Sep 17 00:00:00 2001
From: 0214 <3614157673@qq.com>
Date: Tue, 30 Jan 2024 01:08:30 +0800
Subject: [PATCH 05/14] feat: update searchChannel
---
src/routes/login.svelte | 4 ++
src/routes/searchChannel.svelte | 124 ++++++++++++++++++++++----------
src/store.js | 4 ++
3 files changed, 96 insertions(+), 36 deletions(-)
create mode 100644 src/store.js
diff --git a/src/routes/login.svelte b/src/routes/login.svelte
index 862869e..a6d5666 100644
--- a/src/routes/login.svelte
+++ b/src/routes/login.svelte
@@ -3,6 +3,7 @@
import { onDestroy } from "svelte";
import PocketBase from "pocketbase";
import { PocketBase_URL } from "../utils/api/index";
+ import { currentUserEmail } from "../store.js";
const pb = new PocketBase(PocketBase_URL);
let username = "";
@@ -14,6 +15,9 @@
.collection("users")
.authWithPassword(username, password);
if (userData) {
+ currentUserEmail.set(username);
+ const userEmail = $currentUserEmail;
+ console.log("当前用户的电子邮件:", userEmail);
push("/main");
}
} catch (error) {
diff --git a/src/routes/searchChannel.svelte b/src/routes/searchChannel.svelte
index a9fb59b..6000e68 100644
--- a/src/routes/searchChannel.svelte
+++ b/src/routes/searchChannel.svelte
@@ -2,20 +2,31 @@
import PocketBase from "pocketbase";
import { push } from "svelte-spa-router";
import { PocketBase_URL } from "../utils/api/index";
+ import { currentUserEmail } from "../store.js";
+
// 实例化 PocketBase
const pb = new PocketBase(PocketBase_URL);
- let name = ""; // 绑定到输入框的变量,用于存储用户输入的频道名称
+ let channelNameInput = ""; // 用于存储用户输入的频道名称
let searchResults = []; // 存储搜索结果的数组
let errorMessage = ""; // 存储错误信息
+ // 搜索频道的函数
async function searchChannel() {
try {
errorMessage = "";
+ const userEmail = $currentUserEmail;
const records = await pb
.collection("channels")
- .getFullList({ filter: `channelName="${name}"` });
- searchResults = records;
+ .getFullList({ filter: `channelName="${channelNameInput}"` });
+ searchResults = await Promise.all(
+ records.map((channel) =>
+ checkUserJoinedChannel(channel.channelName, userEmail).then(
+ (isJoined) => ({ ...channel, isJoined }),
+ ),
+ ),
+ );
+
if (records.length === 0) {
errorMessage = "没有找到相关频道。";
}
@@ -25,12 +36,40 @@
}
}
+ // 检查用户是否加入了频道
+ async function checkUserJoinedChannel(channelName, userEmail) {
+ try {
+ const records = await pb.collection("users_channels").getFullList({
+ filter: `useremail="${userEmail}" && channelname="${channelName}"`,
+ });
+ return records.length > 0;
+ } catch (error) {
+ console.error("检查用户频道时发生错误:", error);
+ return false;
+ }
+ }
+
+ // 用户加入频道
+ async function joinChannel(channelname) {
+ try {
+ const userEmail = $currentUserEmail;
+ await pb.collection("users_channels").create({
+ useremail: userEmail,
+ channelname: channelname,
+ });
+ alert("已成功加入频道");
+ } catch (error) {
+ console.error("加入频道时发生错误:", error);
+ alert("加入频道时发生错误:" + error.message);
+ }
+ }
+
// 导航到频道详情页
- function ToChannel(channelName) {
+ function navigateToChannelDetail(channelName) {
push(`/channelDetail/${channelName}`);
}
- // 按下 Enter 键时触发搜索
+ // 处理 Enter 键触发的搜索
function handleKeyPress(event) {
if (event.key === "Enter") {
searchChannel();
@@ -39,11 +78,12 @@
查找频道
+
@@ -52,54 +92,66 @@
{#if errorMessage}
{errorMessage}
{:else if searchResults.length > 0}
-
- {#each searchResults as channel}
- -
- {channel.channelName}
-
+ {channel.channelName} - {channel.channelDescription}
+ {#if channel.isJoined}
+ 已加入
+ {:else}
+
-
- {/each}
-
-{:else if name !== ""}
+ {/if}
+
+
+ {/each}
+{:else if channelNameInput !== ""}
没有找到相关频道。
{/if}
diff --git a/src/store.js b/src/store.js
new file mode 100644
index 0000000..d9c75fe
--- /dev/null
+++ b/src/store.js
@@ -0,0 +1,4 @@
+import { writable } from "svelte/store";
+
+export const currentUserEmail = writable("");
+//在不同的组件间共享当前用户的电子邮件地址。
From 2e391041b87d198df400b1f0dc00042fdeafdb7a Mon Sep 17 00:00:00 2001
From: 0214 <3614157673@qq.com>
Date: Tue, 30 Jan 2024 01:28:05 +0800
Subject: [PATCH 06/14] refactor: refactor createChannel
---
src/routes/createChannel.svelte | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/routes/createChannel.svelte b/src/routes/createChannel.svelte
index a5ed57b..0318b9f 100644
--- a/src/routes/createChannel.svelte
+++ b/src/routes/createChannel.svelte
@@ -29,7 +29,7 @@
};
try {
- const createdChannel = await pb.collection("channels").create(data);
+ await pb.collection("channels").create(data);
alert("Channel created successfully");
isLoading = false;
push("/main");
From e2510d1464143afc6983fda56cc00af66dfe9f13 Mon Sep 17 00:00:00 2001
From: 0214 <3614157673@qq.com>
Date: Sun, 10 Mar 2024 14:28:39 +0800
Subject: [PATCH 07/14] feat: add useremail for a channel
---
src/routes/createChannel.svelte | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/routes/createChannel.svelte b/src/routes/createChannel.svelte
index 0318b9f..241525b 100644
--- a/src/routes/createChannel.svelte
+++ b/src/routes/createChannel.svelte
@@ -2,14 +2,16 @@
import { push } from "svelte-spa-router";
import PocketBase from "pocketbase";
import { PocketBase_URL } from "../utils/api/index";
-
+ import { get } from 'svelte/store'; // 引入 get 函数来同步读取 Svelte 存储的值
+ import { currentUserEmail } from "../store.js";
const pb = new PocketBase(PocketBase_URL);
let channelName = "";
let channelDescription = "";
- let isLoading = false; // 新增:用于跟踪提交状态
+ let isLoading = false;
async function handleCreate() {
isLoading = true;
+ const userEmail = get(currentUserEmail); // 同步获取当前用户邮箱
// 检查频道名是否已存在
const existingChannels = await pb
@@ -26,6 +28,7 @@
const data = {
channelName: channelName,
channelDescription: channelDescription,
+ useremail: userEmail // 添加用户邮箱字段
};
try {
From cfeacc2ff575739ba879c047746374186710cfa0 Mon Sep 17 00:00:00 2001
From: 0214 <3614157673@qq.com>
Date: Sun, 10 Mar 2024 14:29:49 +0800
Subject: [PATCH 08/14] feat: can choose the channels your created
---
src/routes/Modal.svelte | 18 ++++--
src/routes/mychannel.svelte | 125 +++++++++++++++++++++++++++---------
2 files changed, 110 insertions(+), 33 deletions(-)
diff --git a/src/routes/Modal.svelte b/src/routes/Modal.svelte
index 0083f57..8a464ec 100644
--- a/src/routes/Modal.svelte
+++ b/src/routes/Modal.svelte
@@ -36,13 +36,23 @@
display: flex;
justify-content: center;
align-items: center;
- z-index: 1000; /* 确保这个值足够高 */
+ z-index: 1000;
}
.modal-content {
- background: rgb(199, 195, 195);
- padding: 20px;
- border-radius: 8px;
+ background: #333; /* 暗色主题背景 */
+ color: #ccc; /* 浅色文字 */
+ padding: 2rem;
+ border-radius: 12px;
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5); /* 更为显著的阴影效果 */
+ width: auto;
+ max-width: 600px;
position: relative;
+ display: flex;
+ flex-direction: column;
+ overflow: hidden;
}
+
+
+
diff --git a/src/routes/mychannel.svelte b/src/routes/mychannel.svelte
index e110ce1..67eaacc 100644
--- a/src/routes/mychannel.svelte
+++ b/src/routes/mychannel.svelte
@@ -1,4 +1,3 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {#if currentTab === 'joined'}
-
- {#each records as record}
-
- {/each}
-
- {/if}
- {#if currentTab === 'created'}
-
- {#each createdChannels as channel}
-
- {/each}
-
- {/if}
-
-
-
-
From 8e36d9296a76f3f09ca19ba4a68ce4fa9d05714a Mon Sep 17 00:00:00 2001
From: 0214 <3614157673@qq.com>
Date: Tue, 12 Mar 2024 01:38:11 +0800
Subject: [PATCH 10/14] feat: Added channel deletion and modification
---
src/router.js | 1 -
src/routes/EditChannelModal.svelte | 63 +++++++++++++++++++
src/routes/mainpage.svelte | 99 +++++++++++++++++++++++++++++-
3 files changed, 159 insertions(+), 4 deletions(-)
create mode 100644 src/routes/EditChannelModal.svelte
diff --git a/src/router.js b/src/router.js
index 0b12680..e9a1c1b 100644
--- a/src/router.js
+++ b/src/router.js
@@ -11,7 +11,6 @@ import SelectTags from "./routes/selectTags.svelte";
import Mynotice from "./routes/mynotice.svelte";
import Chantemplate from "./routes/chantemplate.svelte";
import Checknotice from "./routes/checknotice.svelte";
-
export default {
"/": DoorPage,
"/login": Login,
diff --git a/src/routes/EditChannelModal.svelte b/src/routes/EditChannelModal.svelte
new file mode 100644
index 0000000..8af97ba
--- /dev/null
+++ b/src/routes/EditChannelModal.svelte
@@ -0,0 +1,63 @@
+
+
+
dispatch("close")}>
+
+
diff --git a/src/routes/mainpage.svelte b/src/routes/mainpage.svelte
index e3373c6..e775708 100644
--- a/src/routes/mainpage.svelte
+++ b/src/routes/mainpage.svelte
@@ -4,6 +4,7 @@
import { PocketBase_URL } from "../utils/api/index";
import { onMount } from "svelte";
import Modal from "./Modal.svelte";
+ import EditChannelModal from "./EditChannelModal.svelte";
import {
currentUserEmail,
currentchannelid,
@@ -19,6 +20,55 @@
let showModal2 = false;
let showModal3 = false;
let showModal4 = false;
+ let selectedChannel = null;
+
+ function editChannel(channelName) {
+ const channel = createdChannels.find((c) => c.channelName === channelName);
+ if (channel) {
+ selectedChannel = channel;
+ }
+ }
+
+ function handleUpdate() {
+ fetchCreatedChannels(); // 重新获取频道列表
+ checkchan();
+ selectedChannel = null; // 重置selectedChannel,关闭编辑模态框
+ }
+
+ async function deleteChannel(channelName) {
+ if (!confirm("确定要删除这个频道吗?")) {
+ return; // 用户取消操作,直接返回
+ }
+
+ try {
+ // 查找channels集合中的指定频道
+ const channels = await pb.collection("channels").getFullList({
+ filter: `channelName="${channelName}"`,
+ });
+ for (const channel of channels) {
+ // 删除找到的频道
+ await pb.collection("channels").delete(channel.id);
+ }
+
+ // 查找并删除users_channels集合中所有与该频道相关的条目
+ const userChannels = await pb.collection("users_channels").getFullList({
+ filter: `channelname="${channelName}"`,
+ });
+ for (const userChannel of userChannels) {
+ await pb.collection("users_channels").delete(userChannel.id);
+ }
+ // 使用.filter()方法移除条目后直接赋值
+ createdChannels = createdChannels.filter(
+ (channel) => channel.channelName !== channelName,
+ );
+ fetchCreatedChannels(); // 重新获取频道列表
+ checkchan();
+ alert("频道及相关数据删除成功。");
+ } catch (error) {
+ console.error("删除频道及相关数据失败:", error);
+ alert("删除频道及相关数据失败。");
+ }
+ }
async function checkchan() {
try {
@@ -161,12 +211,29 @@
{#if currentTab === "created"}
{#each createdChannels as channel}
-
+
+
+
+
+
{/each}
{/if}
+ {#if selectedChannel}
+
(selectedChannel = null)}
+ />
+ {/if}
+
+
+
{$username}
+
+
+
+
+
+
+
+
Channels
+
+ {#each channels as channel}
+
navigateToChannelDetail(channel.channelname)}
+ >
+ {channel.channelname}
+
+ {/each}
+
+
+
+
+
+
Todos
+
+ {#each todos as todo}
+
navigateToTodoDetail(todo.tittle)}
+ >
+ {todo.tittle}
+
+ {/each}
+
+
+
+
+
+
From 7b838b78b3bdd440333aa2a5e1f2ed1d0cf9ec48 Mon Sep 17 00:00:00 2001
From: 0214 <3614157673@qq.com>
Date: Sun, 17 Mar 2024 00:48:00 +0800
Subject: [PATCH 12/14] feat: lead Profile to the mainpage
---
src/routes/mainpage1.svelte | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/routes/mainpage1.svelte b/src/routes/mainpage1.svelte
index 069fb81..94563a8 100644
--- a/src/routes/mainpage1.svelte
+++ b/src/routes/mainpage1.svelte
@@ -81,12 +81,12 @@
Channels
{#each channels as channel}
-
navigateToChannelDetail(channel.channelname)}
>
{channel.channelname}
-
+
{/each}
@@ -96,12 +96,12 @@