feat: todo list

This commit is contained in:
Mike 2023-12-26 07:04:00 -08:00
parent 551b6206ad
commit eaea3ef869
7 changed files with 4485 additions and 0 deletions

132
todo/.gitignore vendored Normal file
View file

@ -0,0 +1,132 @@
# ---> Node
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

3
todo/README.md Normal file
View file

@ -0,0 +1,3 @@
# webpack-template
Vanilla template for webpack

4163
todo/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

23
todo/package.json Normal file
View file

@ -0,0 +1,23 @@
{
"name": "todo",
"version": "1.0.0",
"description": "Todolist project",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "webpack --watch",
"start": "webpack serve --open",
"build": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"css-loader": "^6.8.1",
"html-webpack-plugin": "^5.6.0",
"style-loader": "^3.3.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
}
}

113
todo/src/components/todo.js Normal file
View file

@ -0,0 +1,113 @@
function createTodo(title, description, dueDate, pomodoros) {
let _todo = {
title: title,
description: description,
dueDate: dueDate,
pomodoros: pomodoros,
completed: false
}
return _todo;
}
function editTodo(_todo, title, description, dueDate, pomodoros) {
if (description) _todo.description = description;
if (dueDate) _todo.dueDate = dueDate;
if (pomodoros) _todo.pomodors = pomodoros;
}
function deleteTodo() {
}
function createProject(name) {
let project = {
name: name,
todos: []
}
return project;
}
function todoHandler() {
// Create default project during construction
this.projects = [new createProject('default')];
const getTodos = () => {
return this.projects.map(item => item.todos);
}
const addTodo = (project = 'default', title, description, dueDate, pomodoros) => {
let index = this.projects.findIndex(x => x.name === project);
let _titleExists = titleExists(title, this.projects[index].todos);
if (!_titleExists) {
this.projects[index].todos.push(new createTodo(title, description, dueDate, pomodoros));
} else {
console.log('unable to create duplicate note');
return
}
}
const editTodo = (project, title, description, dueDate, pomodors) => {
let projectIndex = this.projects.findIndex(x => x.name === project);
let todo = this.projects[projectIndex].todos.find(t => t.title === title)
if (todo){
if(description) todo.description = description;
if(dueDate) todo.dueDate = dueDate;
if(pomodors) todo.pomodoros = pomodors;
}
}
const deleteTodo = (project, title) => {
let projectIndex = this.projects.findIndex(x => x.name === project);
let tempArr = this.projects[projectIndex].todos.filter(item => {
if (item.title !== title){
return item;
};
});
this.projects[projectIndex].todos = tempArr;
}
const titleExists = (title, todoArr) => {
return todoArr.find(todo => todo.title === title);
}
const addProject = name => this.projects.push(createProject(name));
const getProjects = () => {
return this.projects.map(item => item.name);
}
const delProject = name => {
let index = this.projects.findIndex(proj => proj.name === name);
let tempArr = this.projects.filter(item => {
if (item !== this.projects[index] || name === 'default' ){
return item;
};
});
this.projects = tempArr;
}
return { getTodos, addTodo, editTodo, deleteTodo, addProject, getProjects, delProject }
}
export { todoHandler };
// let todos = todoHandler();
// todos.addTodo('default', 'test', 'some stuff', 'today', 5);
// todos.addProject('chores');
// todos.addTodo('default', 'test default 2', 'some stuff', 'today', 5);
// todos.addTodo('chores', 'choretest', 'some stuff', 'today', 5);
// console.log(todos.getTodos());
// todos.delProject('de');
// todos.editTodo('default', 'test', 'stuffing', 'tomorrow', 4);
// console.log(todos.getTodos());
// todos.deleteTodo('chores', 'choretest');
// console.log(todos.getTodos());

12
todo/src/index.js Normal file
View file

@ -0,0 +1,12 @@
// todoHandler().addTodo('default', 'test', 'some stuff', 'today', 5);
// todos.addProject('chores');
// todos.addTodo('default', 'test default 2', 'some stuff', 'today', 5);
// todos.addTodo('chores', 'choretest', 'some stuff', 'today', 5);
// console.log(todos.getTodos());
// todos.delProject('de');
// todos.editTodo('default', 'test', 'stuffing', 'tomorrow', 4);
// console.log(todos.getTodos());
// todos.deleteTodo('chores', 'choretest');
// console.log(todos.getTodos());

39
todo/webpack.config.js Normal file
View file

@ -0,0 +1,39 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
mode: 'development',
entry: {
index: './src/index.js',
},
plugins: [
new HtmlWebpackPlugin({
title: 'Todo',
}),
],
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
clean: true,
},
devtool: 'inline-source-map',
devServer: {
static: './dist',
},
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
],
},
};