From 51d8643b8afe6f77065107b57d153e6f5c40ba77 Mon Sep 17 00:00:00 2001 From: 0214 <3614157673@qq.com> Date: Thu, 25 Jan 2024 01:37:04 +0800 Subject: [PATCH 01/14] add a new page to search channels --- src/routes/searchChannel.svelte | 106 +++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/src/routes/searchChannel.svelte b/src/routes/searchChannel.svelte index 24eb70a..035f7ed 100644 --- a/src/routes/searchChannel.svelte +++ b/src/routes/searchChannel.svelte @@ -1 +1,105 @@ -

search channels

+ + +

查找频道

+
+ + +
+ +{#if errorMessage} +

{errorMessage}

+{:else if searchResults.length > 0} + +{:else if name !== ""} +

没有找到相关频道。

+{/if} + + From 85454deae866cc595d9f7add6fb716b1b5de5d18 Mon Sep 17 00:00:00 2001 From: 0214 <3614157673@qq.com> Date: Sat, 27 Jan 2024 16:09:58 +0800 Subject: [PATCH 02/14] Updated createchannel --- src/routes/createChannel.svelte | 21 ++++++++++++++++++--- src/routes/searchChannel.svelte | 4 ++-- src/utils/api/index.js | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/routes/createChannel.svelte b/src/routes/createChannel.svelte index 34ca7d6..c32e8e7 100644 --- a/src/routes/createChannel.svelte +++ b/src/routes/createChannel.svelte @@ -1,17 +1,29 @@ -

Create your channel

+

Create Your Channel

-
-
-
- -
-
- -
+ +
+ +
+
+
- + {#if isLoading} +

Loading...

+ {:else} + + {/if} + + \ 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 @@
    - +
    - +
    {#if isLoading}

    Loading...

    @@ -53,50 +66,50 @@
    \ 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} +
    + User Profile +

    {$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 @@

    Todos

    {#each todos as todo} -
    navigateToTodoDetail(todo.tittle)} > {todo.tittle} -
    + {/each}
    From 12069ca84fbbea11ec7b040314dfb14f4521dfaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=AF=E5=B0=8F=E9=9B=A8?= <143722071+03130214@users.noreply.github.com> Date: Sun, 17 Mar 2024 18:56:44 +0800 Subject: [PATCH 13/14] feat: lead Profile to the mainpage (#74) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add a new page to search channels * Updated createchannel * feat: refine createchannel * feat: refine createchannel * feat: update searchChannel * refactor: refactor createChannel * feat: add useremail for a channel * feat: can choose the channels your created * refactor: Refactor the code * feat: Added channel deletion and modification * feat: lead Profile to the mainpage * feat: lead Profile to the mainpage --------- Co-authored-by: My Go! <118411001+Clear1oveE@users.noreply.github.com> --- src/components/Navbar.svelte | 2 +- src/router.js | 2 + src/routes/mainpage1.svelte | 135 +++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 src/routes/mainpage1.svelte diff --git a/src/components/Navbar.svelte b/src/components/Navbar.svelte index 7daaf0a..7f63e83 100644 --- a/src/components/Navbar.svelte +++ b/src/components/Navbar.svelte @@ -81,7 +81,7 @@ >{$username} -
  • Profile
  • +
  • Profile
  • Mychannels
  • Logout
  • diff --git a/src/router.js b/src/router.js index 55eb40f..e24ca71 100644 --- a/src/router.js +++ b/src/router.js @@ -1,5 +1,6 @@ import Login from "./routes/login.svelte"; import MainPage from "./routes/mainpage.svelte"; +import MainPage1 from "./routes/mainpage1.svelte"; import DoorPage from "./routes/doorPage.svelte"; import Register from "./routes/register.svelte"; import CreateChannel from "./routes/createChannel.svelte"; @@ -20,6 +21,7 @@ export default { "/": DoorPage, "/login": Login, "/main": MainPage, + "/main1": MainPage1, "/register": Register, "/createChannel": CreateChannel, "/checkInformation": CheckInformation, diff --git a/src/routes/mainpage1.svelte b/src/routes/mainpage1.svelte new file mode 100644 index 0000000..94563a8 --- /dev/null +++ b/src/routes/mainpage1.svelte @@ -0,0 +1,135 @@ + + + + +
    + +
    + User Profile +

    {$username}

    + +
    + + +
    + +
    +

    Channels

    +
    + {#each channels as channel} + + {/each} +
    +
    + + +
    +

    Todos

    +
    + {#each todos as todo} + + {/each} +
    +
    +
    +
    + + From 1a3512d8dfcc4bab2af3a506be7a9a76b7e867b4 Mon Sep 17 00:00:00 2001 From: 0214 <3614157673@qq.com> Date: Sun, 17 Mar 2024 21:20:50 +0800 Subject: [PATCH 14/14] feat: repair the channels and todos --- src/routes/mainpage1.svelte | 106 ++++++++++++++++++++++++-------- src/routes/searchChannel.svelte | 21 +++++++ 2 files changed, 101 insertions(+), 26 deletions(-) diff --git a/src/routes/mainpage1.svelte b/src/routes/mainpage1.svelte index 94563a8..729ee73 100644 --- a/src/routes/mainpage1.svelte +++ b/src/routes/mainpage1.svelte @@ -4,7 +4,13 @@ import { PocketBase_URL } from "../utils/api/index"; import { onMount } from "svelte"; import Navbar from "../components/Navbar.svelte"; - import { currentUserEmail, username } from "../store.js"; + import { + currentUserEmail, + currentnoticeid, + isJoinedTodo, + username, + originChannelID, + } from "../store.js"; const pb = new PocketBase(PocketBase_URL); let channels = []; // 存储频道数据 @@ -47,12 +53,32 @@ push("/login"); } - function navigateToChannelDetail(channelId) { - push(`/channel-detail/${channelId}`); + function jumpnew(origin) { + originChannelID.set(origin); + push("/chantemplate"); } + async function jumptodo(title) { + const response_ = await pb.collection("notices").getFullList({ + sort: "-created", + filter: `tittle="${title}"`, + }); - function navigateToTodoDetail(todoId) { - push(`/todo-detail/${todoId}`); + currentnoticeid.set(response_[0].id); + const uEmail = $currentUserEmail; + const response = await pb.collection("todolist").getFullList({ + sort: "-created", + filter: `useremail="${uEmail}"`, + }); + + for (const item of response) { + if (item.tittle == title) { + isJoinedTodo.set("find"); + break; + } else { + isJoinedTodo.set("noFind"); + } + } + push("/checknotice"); } @@ -80,10 +106,11 @@

    Channels

    - {#each channels as channel} + {#each channels.slice(0, 6) as channel} + @@ -91,16 +118,16 @@
    - -
    + + +

    Todos

    -
    - {#each todos as todo} - {/each}
    @@ -109,6 +136,17 @@
    diff --git a/src/routes/searchChannel.svelte b/src/routes/searchChannel.svelte index 263b2c6..0bcf3d5 100644 --- a/src/routes/searchChannel.svelte +++ b/src/routes/searchChannel.svelte @@ -75,11 +75,32 @@ async function joinChannel(channelname, channelid) { try { const userEmail = $currentUserEmail; + // 获取当前日期 + const now = new Date(); + const year = now.getFullYear(); + const month = now.getMonth() + 1; // JavaScript的月份是从0开始的 + const day = now.getDate(); + + // 以备选方式获取频道描述 + const records = await pb + .collection("channels") + .getFullList({ filter: `channelName="${channelname}"` }); + if (records.length === 0) { + throw new Error("未找到指定的频道。"); + } + const channelDescription = records[0].channelDescription; + + // 创建记录并包含年月日和频道描述 await pb.collection("users_channels").create({ useremail: userEmail, channelname: channelname, originid: channelid, + year: year, + month: month, + day: day, + channelDescription: channelDescription, // 存储频道描述 }); + alert("已成功加入频道"); navigateToChannelDetail("main"); } catch (error) {