Skip to content

Commit

Permalink
Merge pull request #524 from tishubohra/main
Browse files Browse the repository at this point in the history
subscript_of_bookmark
  • Loading branch information
panwar8279 committed May 27, 2024
2 parents 6a55e96 + d8e4369 commit fc34979
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 129 deletions.
112 changes: 0 additions & 112 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions frontend/src/Component/Navbar/NavbarCenter.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import React from "react";
import { useSelector } from "react-redux";
import "../../style/Navbar.css";
import NavbarItem from "./NavbarItem";

function NavbarCenter(){
function NavbarCenter() {
const totalBookmarks = useSelector((state) => state.SourceReducer.totalBookmarks) || 0;

return (
<span className="navbar-center">
<ul className="mb-2 navbar-content">
<nav className="navbar-center">
<ul className="navbar-content mb-2">
<li className="nav-item">
<NavbarItem description="Home" to="/" />
</li>
<li className="nav-item">
<NavbarItem description="BookMark" to="/bookmark" />
<NavbarItem description={`Bookmark (${totalBookmarks})`} to="/bookmark" />
</li>
<li className="nav-item">
<NavbarItem description="Open Source" to="/open-source"/>
<NavbarItem description="Open Source" to="/open-source" />
</li>
<li className="nav-item">
<NavbarItem description="About Us" to="/about" />
</li>
</ul>
</span>
</nav>
);
};
}

export default NavbarCenter;
8 changes: 4 additions & 4 deletions frontend/src/Component/Navbar/NavbarItem.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from "react";
import { Link } from "react-router-dom";

function NavbarItem({description,to}) {
function NavbarItem({ description, to }) {
return (
<Link to={to} className="Link nav-link active" aria-current="page">
{description}
</Link>
<Link to={to} className="Link nav-link active" aria-current="page">
{description}
</Link>
);
}

Expand Down
20 changes: 15 additions & 5 deletions frontend/src/Slice/DataSlice.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
import { createSlice } from "@reduxjs/toolkit";

// Helper function to get initial bookmarks from local storage
const getInitialBookmarks = () => JSON.parse(localStorage.getItem('bookmarks')) || [];

const DataSlice = createSlice({
name: 'data',
initialState: {
sourceData: JSON.parse(localStorage.getItem('bookmarks')) || []
sourceData: getInitialBookmarks(),
totalBookmarks: getInitialBookmarks().length,
},
reducers: {
setSource: (state, action) => {
state.sourceData.push({
image: action.payload.image,
name: action.payload.name,
desc: action.payload.desc,
link: action.payload.link
link: action.payload.link,
});
state.totalBookmarks = state.sourceData.length;
localStorage.setItem('bookmarks', JSON.stringify(state.sourceData));
},
deleteSource: (state, action) => {
// Find the index of the bookmark to delete by matching the name
const indexToDelete = state.sourceData.findIndex(bookmark => bookmark.name === action.payload.name);
const indexToDelete = state.sourceData.findIndex(
(bookmark) => bookmark.name === action.payload.name
);

if (indexToDelete !== -1) {
// Remove the bookmark from the array by index
state.sourceData.splice(indexToDelete, 1);
state.totalBookmarks = state.sourceData.length;
localStorage.setItem('bookmarks', JSON.stringify(state.sourceData));
}
}
}
},
},
});

export default DataSlice.reducer;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ root.render(
</Provider>
</BrowserRouter>
</React.StrictMode>
);
);

0 comments on commit fc34979

Please sign in to comment.