mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2024-12-26 14:20:43 -05:00
feat: added navbar
This commit is contained in:
parent
f18b11a22b
commit
99a09a0f06
5 changed files with 62 additions and 3 deletions
12
todo/package-lock.json
generated
12
todo/package-lock.json
generated
|
@ -8,6 +8,9 @@
|
|||
"name": "todo",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"date-fns": "^3.0.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"css-loader": "^6.8.1",
|
||||
"html-webpack-plugin": "^5.5.4",
|
||||
|
@ -1071,6 +1074,15 @@
|
|||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/date-fns": {
|
||||
"version": "3.0.6",
|
||||
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-3.0.6.tgz",
|
||||
"integrity": "sha512-W+G99rycpKMMF2/YD064b2lE7jJGUe+EjOES7Q8BIGY8sbNdbgcs9XFTZwvzc9Jx1f3k7LB7gZaZa7f8Agzljg==",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/kossnocorp"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
|
|
|
@ -20,5 +20,8 @@
|
|||
"webpack": "^5.89.0",
|
||||
"webpack-cli": "^5.1.4",
|
||||
"webpack-dev-server": "^4.15.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"date-fns": "^3.0.6"
|
||||
}
|
||||
}
|
||||
|
|
38
todo/src/components/navbar.js
Normal file
38
todo/src/components/navbar.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
function navbar(projects) {
|
||||
let nav = document.createElement('nav');
|
||||
nav.classList.add('nav');
|
||||
|
||||
let projectsDiv = projectButtons(projects);
|
||||
let addProjectBtn = addProject();
|
||||
|
||||
nav.appendChild(projectsDiv);
|
||||
nav.appendChild(addProjectBtn);
|
||||
|
||||
return nav;
|
||||
}
|
||||
|
||||
function projectButtons(projects) {
|
||||
let projectsDiv = document.createElement('div');
|
||||
projectsDiv.classList.add(['projects']);
|
||||
|
||||
projects.forEach(e => {
|
||||
if (e.name !== 'default') {
|
||||
let btn = document.createElement('button');
|
||||
btn.classList.add(['btn', 'project-btn']);
|
||||
btn.textContent = e.name;
|
||||
projectsDiv.append(btn);
|
||||
};
|
||||
});
|
||||
return projectsDiv;
|
||||
}
|
||||
|
||||
function addProject() {
|
||||
let btn = document.createElement('button');
|
||||
btn.classList.add(['btn', 'add-project']);
|
||||
btn.textContent = 'New Project';
|
||||
return btn;
|
||||
|
||||
}
|
||||
|
||||
|
||||
export { navbar };
|
|
@ -85,10 +85,10 @@ class todoHandler {
|
|||
}
|
||||
|
||||
getProjects () {
|
||||
return this.projects.map(item => item.name);
|
||||
return this.projects;
|
||||
}
|
||||
|
||||
delProject = name => {
|
||||
delProject(name) {
|
||||
let index = this.projects.findIndex(proj => proj.name === name);
|
||||
let tempArr = this.projects.filter(item => {
|
||||
if (item !== this.projects[index] || name === 'default' ){
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { navbar } from "./components/navbar";
|
||||
import { todoHandler } from "./components/todo";
|
||||
import { save, load } from "./components/storage";
|
||||
|
||||
let todos; let data = load();
|
||||
let todos;
|
||||
let data = load();
|
||||
|
||||
// if there's local data save it in the array
|
||||
if (data) {
|
||||
|
@ -15,6 +17,10 @@ if (data) {
|
|||
todos.addProject('job');
|
||||
todos.addTodo('default', 'test default 2', 'some stuff', 'today', 5);
|
||||
todos.addTodo('default', 'default 2', 'some stuff', 'today', 5);
|
||||
|
||||
|
||||
document.body.appendChild(navbar(todos.getProjects()));
|
||||
|
||||
// todos.addTodo('chores', 'choretest', 'some stuff', 'today', 5);
|
||||
// todos.delProject('de');
|
||||
// todos.editTodo('default', 'test', 'stuffing', 'tomorrow', 4);
|
||||
|
|
Loading…
Reference in a new issue