How can i add hidden notes Functionality in an notes app made using MERN stack, in Mongoose(for mongodb)

huangapple go评论62阅读模式
英文:

How can i add hidden notes Functionality in an notes app made using MERN stack, in Mongoose(for mongodb)

问题

Sure, here's the translated content:

我想要添加一个隐藏笔记的功能,当我点击隐藏笔记按钮时,该笔记应该从当前位置移除并添加到隐藏笔记中。当我点击隐藏笔记时,我应该能够查看它们,并有选项取消隐藏。请帮忙。

这是我目前完成的网页(隐藏笔记按钮在所有笔记下拉菜单中):

截图1

截图2

截图3

截图4

这是到目前为止完成的笔记应用程序代码(Google Drive链接,不包括node_modules,因为它太大):

Google Drive链接

这是app.js的代码:

import './App.css';
import {
  BrowserRouter as Router,
  Routes,
  Route,
  Link
} from "react-router-dom";
import Navbar from './components/Navbar';
import Home from './components/Home';
import AddNote from "./components/AddNote"
import About from './components/About';
import NoteState from './context/notes/NoteState';
import Alert from './components/Alert';
import Footer from './components/Footer';
import DropDown from './components/DropDown';

function App() {
  return (
    <>
      <NoteState>
        <Router>
          <Navbar />
          <DropDown></DropDown>
          <div className="container">
            <Routes>
              <Route exact path="/" element={<Home />} />
              <Route exact path="/about" element={<About />} />
              <Route exact path="/addnote" element={<AddNote/>} />
            </Routes>
          </div>
          <Alert message="This is amazing React course" />
          <Footer></Footer>
        </Router>
      </NoteState>
    </>
  );
}
export default App;

请帮忙。

英文:

I want to add a hidden notes funcionality in which when i click the hide note button the note should be removed from that place and get added to hidden notes, and when i click on hidden notes i should see them, and even get the option to unhide it, Please help,

Here is the webpage i currently have done(The button for hidden notes is in the all Notes dropdown):

screenshot1

screenshot2

screenshot3

screenshot4

Here is the code for the notes app done till now - (drive File), (without node_modules as it is very heavy):

Code IN Drive

this is app.js:

import &#39;./App.css&#39;;
import {
BrowserRouter as Router,
Routes,
Route,
Link
} from &quot;react-router-dom&quot;;
import Navbar from &#39;./components/Navbar&#39;;
import Home from &#39;./components/Home&#39;;
import AddNote from &quot;./components/AddNote&quot;
import About from &#39;./components/About&#39;;
import NoteState from &#39;./context/notes/NoteState&#39;;
import Alert from &#39;./components/Alert&#39;;
import Footer from &#39;./components/Footer&#39;;
import DropDown from &#39;./components/DropDown&#39;;

function App() {
 return (
    &lt;&gt;
      &lt;NoteState&gt;
        &lt;Router&gt;
          &lt;Navbar /&gt;
          &lt;DropDown&gt;&lt;/DropDown&gt;
          &lt;div className=&quot;container&quot;&gt;
           &lt;Routes&gt;
              &lt;Route exact path=&quot;/&quot; element={&lt;Home /&gt;} /&gt;
              &lt;Route exact path=&quot;/about&quot; element={&lt;About /&gt;} /&gt;
              &lt;Route exact path=&quot;/addnote&quot; element={&lt;AddNote/&gt;} /&gt;
            &lt;/Routes&gt;
          &lt;/div&gt;
          &lt;Alert message=&quot;This is amazing React course&quot; /&gt;
          &lt;Footer&gt;&lt;/Footer&gt;
        &lt;/Router&gt;
      &lt;/NoteState&gt;
    &lt;/&gt;
  );
}
export default App;

Please Help

答案1

得分: 1

  1. 创建一个名为"notes"的表格。

    1.1. 这个表格应该有一个名为"isVisible"的字段。这个字段的数据类型将是布尔型,并且默认值设置为true。

  2. 创建一个API来改变笔记的可见性,方法应该是"PATCH"。

  3. 创建一个API来获取所有笔记的列表。在请求参数中,您需要添加一个参数,即isVisible,根据参数的值,API将返回数据。

    例如,如果您想显示所有隐藏的笔记,那么您的后端URL将如下所示:http://localhost:3000/api/notes?isVisible=false

英文:
  1. Create a table named "notes"

    1.1. The table should have a field named "isVisible". The data type of this field will be boolean and by default the value is set to true.

  2. Create an API to change the visibility of the note, the method should be "PATCH".

  3. Create an API to fetch the list of all the notes. In request parameters you have to add one parameter i.e.,isVisible and based on the value of the parameter the API will return the data.

    For example if you want to show all the hidden notes then your backend URL will look like http://localhost:3000/api/notes?isVisible=false

答案2

得分: 0

这取决于你希望如何保存数据,我通常会按照以下逻辑编写代码:
1)获取你想隐藏的项目的ID。
2)将项目ID添加到隐藏列表中(将其保存到数据库中)。
3)在加载笔记数据之前,你应该根据隐藏列表中存储的ID来过滤掉相应的ID。

       let currNotesData = notesData.filter((notes) => {
         return hiddenList.includes(notes);
       })

4)然后,你可以遍历currNotesData并渲染可用的组件。

这也有其他的方法可以做到。

英文:

It depends how you want to save the data, I would normally write the logic like this:

  1. get the id of the item you want to hide
  2. push the item id to the hidden list (save it to the database)
  3. before you load the notes data, you should filter out the id based on the id stored in the hidden list.
       let currNotesData = notesData.filter((notes) =&gt; {
         return hiddenList.includes(notes) })
  1. Then, you can loop through the currNotesData and render the available component.

There are more ways to do this too

huangapple
  • 本文由 发表于 2023年5月22日 15:05:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76303722.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定