From e3d3911a877f34640244b39cb4c587a932d419aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=8C=E8=97=A4=E3=81=B2=E3=81=A8=E3=82=8A?= <118675237+babuzeer@users.noreply.github.com> Date: Mon, 18 Mar 2024 22:35:03 +0800 Subject: [PATCH] Ismain (#90) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add notices to a new collection the new collection named todolist, and there are small changes about how the pages look like. * feat: add notices to a new collection * style: update npm and run format * style: run npm format again * feat: lead Profile to the mainpage (#74) * 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> * feat: refine the searching part --------- Co-authored-by: sheeplin <1270610465@qq.com> Co-authored-by: My Go! <118411001+Clear1oveE@users.noreply.github.com> Co-authored-by: 路小雨 <143722071+03130214@users.noreply.github.com> --- src/components/searchlan.svelte | 109 +++++++++++++++++--------------- src/router.js | 3 + src/routes/checknotice.svelte | 1 + src/routes/mainpage.svelte | 4 -- 4 files changed, 63 insertions(+), 54 deletions(-) diff --git a/src/components/searchlan.svelte b/src/components/searchlan.svelte index 156187e..a62c220 100644 --- a/src/components/searchlan.svelte +++ b/src/components/searchlan.svelte @@ -7,12 +7,12 @@ const pb = new PocketBase(PocketBase_URL); let searchQuery = ""; - // let isMainPage = true; let errorMessage = ""; let searchchannels = []; let searchnotices = []; let searchtags = []; let isFocused = false; + let isMainPage = false; function jumpnew(id) { originChannelID.set(id); @@ -38,56 +38,80 @@ isFocused = false; } } - // function isid() { - // if ($currentchannelid != null) isMainPage = false; - // } - // function search(){ - // alert(isMainPage); - // } + function isid() { + if (window.location.href === "http://localhost:5173/#/main") { + isMainPage = true; + } else { + isMainPage = false; + } + } + async function search() { errorMessage = ""; try { // 获取所有频道及通知记录 const allRecords = await pb.collection("channels").getFullList(); const allnotices = await pb.collection("notices").getFullList(); - // 根据输入过滤并限制结果数量为最多4个 - if (searchQuery.length > 0) { - const filteredRecords = allRecords.filter((record) => - record.channelName.startsWith(searchQuery), - ); - const limitedRecords = filteredRecords.slice(0, 4); - searchchannels = limitedRecords; + if (isMainPage) { + if (searchQuery.length > 0) { + const filteredRecords = allRecords.filter((record) => + record.channelName.startsWith(searchQuery), + ); + searchchannels = filteredRecords; - const filterednotices = allnotices.filter((record) => - record.tittle.startsWith(searchQuery), - ); - const limitednotices = filterednotices.slice(0, 4); - searchnotices = limitednotices; + const filterednotices = allnotices.filter((record) => + record.tittle.startsWith(searchQuery), + ); + searchnotices = filterednotices; - const filteredtags = allnotices.filter((record) => - record.tag.startsWith(searchQuery), - ); - const limitedtags = filteredtags.slice(0, 4); - searchtags = limitedtags; - if ( - limitedRecords.length === 0 && - limitednotices.length === 0 && - limitedtags.length === 0 - ) { - errorMessage = "没有找到相关频道或通知。"; + const filteredtags = allnotices.filter((record) => + record.tag.startsWith(searchQuery), + ); + searchtags = filteredtags; + if ( + searchchannels.length === 0 && + searchnotices.length === 0 && + filteredtags.length === 0 + ) { + errorMessage = "没有找到相关频道或通知。"; + } + } else { + searchchannels = []; + searchnotices = []; + searchtags = []; } } else { - searchchannels = []; - searchnotices = []; + //当前页面不是主页时 + if (searchQuery.length > 0) { + const filterednotices = allnotices.filter( + (record) => + record.tittle.startsWith(searchQuery) && + record.channelid == $originChannelID, + ); + searchnotices = filterednotices; + + const filteredtags = allnotices.filter( + (record) => + record.tag.startsWith(searchQuery) && + record.channelid == $originChannelID, + ); + searchtags = filteredtags; + if (searchnotices.length === 0 && searchtags.length === 0) { + errorMessage = "没有找到相关通知。"; + } + } else { + searchtags = []; + searchnotices = []; + } } } catch (error) { - console.error("搜索频道时发生错误:", error); - errorMessage = "搜索频道时发生错误:" + error.message; + console.error("搜索通知时发生错误:", error); + errorMessage = "搜索通知时发生错误:" + error.message; } } onMount(() => { - // isid(); + isid(); document.addEventListener("click", handleClickOutside); }); onDestroy(() => { @@ -104,7 +128,6 @@ placeholder="search everything..." on:focus={() => (isFocused = true)} /> - {#if errorMessage}
.record { width: auto; + height: 98%; border: 1px solid #ccc; padding: 15px; margin: 10px 0; diff --git a/src/routes/mainpage.svelte b/src/routes/mainpage.svelte index 1c76f78..0b7b8f9 100644 --- a/src/routes/mainpage.svelte +++ b/src/routes/mainpage.svelte @@ -27,9 +27,6 @@ let showtodo = true; let selectedChannel = null; - function ismain() { - currentchannelid.set(null); - } function editChannel(channelName) { currentchannelName.set(channelName); push("/updateChannel"); @@ -249,7 +246,6 @@ checkNotice(); fetchCreatedChannels(); checkTodolist(); - ismain(); }); let src = "userPicture.jpeg";