Skip to content

Commit

Permalink
Ismain (#90)
Browse files Browse the repository at this point in the history
* 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! <[email protected]>

* feat: refine the searching part

---------

Co-authored-by: sheeplin <[email protected]>
Co-authored-by: My Go! <[email protected]>
Co-authored-by: 路小雨 <[email protected]>
  • Loading branch information
4 people authored Mar 18, 2024
1 parent 0c1705b commit e3d3911
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 54 deletions.
109 changes: 59 additions & 50 deletions src/components/searchlan.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(() => {
Expand All @@ -104,7 +128,6 @@
placeholder="search everything..."
on:focus={() => (isFocused = true)}
/>
<button on:click={() => search()}>search</button>
{#if errorMessage}
<div class="searchdrop">
<div
Expand Down Expand Up @@ -202,20 +225,6 @@
width: 400px;
border-color: #007bff;
}
button {
padding: 8px 15px;
font-size: 16px;
background-color: #c8c8c8;
color: white;
border: none;
border-radius: 16px;
cursor: pointer;
margin-left: 10px;
outline: none;
}
button:hover {
background-color: #0056b3;
}
.channame {
display: flex; /* 启用Flexbox布局 */
align-items: center; /* 垂直居中 */
Expand Down
3 changes: 3 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import Jumptag from "./routes/jumptag.svelte";
import InfoPage from "./routes/infoPage.svelte";
import Updatenotice from "./routes/updatenotice.svelte";
import Mychannels from "./routes/myChannels.svelte";
import Searchresult from "./routes/searchresult.svelte";

export default {
"/": DoorPage,
"/login": Login,
Expand All @@ -37,4 +39,5 @@ export default {
"/infoPage": InfoPage,
"/updatenotice": Updatenotice,
"/myChannels": Mychannels,
"/searchresult": Searchresult,
};
1 change: 1 addition & 0 deletions src/routes/checknotice.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<style>
.record {
width: auto;
height: 98%;
border: 1px solid #ccc;
padding: 15px;
margin: 10px 0;
Expand Down
4 changes: 0 additions & 4 deletions src/routes/mainpage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
let showtodo = true;
let selectedChannel = null;
function ismain() {
currentchannelid.set(null);
}
function editChannel(channelName) {
currentchannelName.set(channelName);
push("/updateChannel");
Expand Down Expand Up @@ -249,7 +246,6 @@
checkNotice();
fetchCreatedChannels();
checkTodolist();
ismain();
});
let src = "userPicture.jpeg";
Expand Down

0 comments on commit e3d3911

Please sign in to comment.