-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 12f0ac0
Showing
21 changed files
with
6,161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
|
||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const {ipcRenderer} = require('electron'); | ||
|
||
const addForm = document | ||
.querySelector('.todo__add-form') | ||
.addEventListener('submit',function(event){ | ||
event.preventDefault(); | ||
const item = document.querySelector('.todo__add-input'); | ||
ipcRenderer.send('addTodo',item.value); | ||
item.value = ''; | ||
}) | ||
|
||
const closeBtn = document | ||
.querySelector('.icon-tab-close') | ||
.addEventListener('click',function(event){ | ||
ipcRenderer.send('manageWindow','closeAdd'); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { ipcRenderer } = require("electron") | ||
|
||
const fadeOut = item=>{ | ||
item.classList.add('todo__item--close'); | ||
return new Promise((resolve,reject)=>{ | ||
setTimeout(() => { | ||
resolve('success'); | ||
}, 500); | ||
}) | ||
} | ||
|
||
async function deleteitem(event){ | ||
const item = this.previousSibling.innerText; | ||
await fadeOut(this.parentElement); | ||
this.parentElement.remove(); | ||
ipcRenderer.send('deleteTodo',item); | ||
} | ||
|
||
function attachDeleteEvent(item){ | ||
const button = item.childNodes[1]; | ||
button.addEventListener('click',deleteitem); | ||
} | ||
|
||
module.exports = { | ||
deleteitem:deleteitem, | ||
attachDeleteEvent:attachDeleteEvent, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const {attachDeleteEvent} = require('./deleteEvent.js'); | ||
|
||
let dragSrcElement; | ||
|
||
function handleDragStart(event){ | ||
this.style.opacity='0.4'; | ||
dragSrcElement = this; | ||
event.dataTransfer.effectAllowed = 'move'; | ||
event.dataTransfer.setData('text/html',this.innerHTML); | ||
return false; | ||
} | ||
|
||
function handleDragEnter(event){ | ||
this.classList.add('over'); | ||
return false; | ||
} | ||
|
||
function handleDragOver(event){ | ||
if(event.preventDefault){ | ||
event.preventDefault(); | ||
} | ||
return false; | ||
} | ||
|
||
function handleDragLeave(event){ | ||
this.classList.remove('over'); | ||
return false; | ||
} | ||
|
||
function handleDragEnd(event){ | ||
this.style.opacity = ''; | ||
document.querySelectorAll('.todo__item').forEach(todo=>{ | ||
todo.classList.remove('over'); | ||
}) | ||
return false; | ||
} | ||
|
||
function handleDrop(event){ | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
if(dragSrcElement!==this){ | ||
dragSrcElement.innerHTML = this.innerHTML; | ||
this.innerHTML = event.dataTransfer.getData('text/html'); | ||
attachDeleteEvent(this); | ||
attachDeleteEvent(dragSrcElement); | ||
} | ||
return false; | ||
} | ||
|
||
function attachDragEvent(todo){ | ||
todo.addEventListener('dragstart',handleDragStart); | ||
todo.addEventListener('dragenter',handleDragEnter) | ||
todo.addEventListener('dragover',handleDragOver); | ||
todo.addEventListener('dragleave',handleDragLeave); | ||
todo.addEventListener('drop',handleDrop); | ||
todo.addEventListener('dragend',handleDragEnd); | ||
} | ||
|
||
module.exports= { | ||
handleDragStart:handleDragStart, | ||
handleDragEnter:handleDragEnter, | ||
handleDragOver:handleDragOver, | ||
handleDragLeave:handleDragLeave, | ||
handleDragEnd:handleDragEnd, | ||
handleDrop:handleDrop, | ||
attachDragEvent:attachDragEvent | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const{app,BrowserWindow, ipcMain} = require('electron'); | ||
const dataStore = require('./model/dataStore.js'); | ||
const positionStore = require('./model/position.js'); | ||
|
||
let todoWindow,addWindow; | ||
|
||
const position = new positionStore(); | ||
|
||
function showTodo(){ | ||
todoWindow = new BrowserWindow({ | ||
width:600, | ||
height:900, | ||
frame:false, | ||
x:position.x, | ||
y:position.y, | ||
resizable:false, | ||
show:false, | ||
webPreferences:{ | ||
contextIsolation:false, | ||
nodeIntegration:true | ||
} | ||
}) | ||
todoWindow.webContents.loadFile('./view/todo.html'); | ||
} | ||
|
||
function addTodo(){ | ||
const pos = todoWindow.getPosition(); | ||
addWindow = new BrowserWindow({ | ||
width:450, | ||
height:300, | ||
x:pos[0]+75, | ||
y:pos[1]+300, | ||
frame:false, | ||
resizable:false, | ||
roundedCorners:true, | ||
webPreferences:{ | ||
contextIsolation:false, | ||
nodeIntegration:true | ||
} | ||
}) | ||
addWindow.webContents.loadFile('./view/add.html'); | ||
} | ||
|
||
const todoStore = new dataStore(); | ||
|
||
app.whenReady() | ||
.then(async()=>{ | ||
showTodo(); | ||
todoWindow.webContents.once('did-finish-load',(event,message)=>{ | ||
todoWindow.webContents.send('todos',todoStore.getTodo()); | ||
todoWindow.show(); | ||
}) | ||
todoWindow.on('close',(event)=>{ | ||
const pos = todoWindow.getPosition(); | ||
console.log(pos); | ||
position.savePos(pos[0],pos[1]); | ||
}) | ||
}) | ||
|
||
|
||
|
||
ipcMain.on('deleteTodo',(event,item)=>{ | ||
todoStore.deleteTodo(item); | ||
todoWindow.webContents.send('todo-result',`${item} Complete!`); | ||
}) | ||
|
||
ipcMain.on('addTodo',(event,todo)=>{ | ||
todoStore.addTodo(todo); | ||
todoWindow.webContents.send('newTodo',todo); | ||
}) | ||
|
||
ipcMain.on('addTodoWindow',(event,message)=>{ | ||
addTodo(); | ||
}) | ||
|
||
ipcMain.on('manageWindow',(event,message)=>{ | ||
if(message==='minimize'){ | ||
todoWindow.minimize(); | ||
}else if(message==='closeAdd'){ | ||
addWindow.destroy(); | ||
addWindow = null; | ||
todoWindow.webContents.send('todo-result','Adding complete'); | ||
} | ||
else if(message==='close'){ | ||
todoWindow.close(); | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const Store = require('electron-store'); | ||
|
||
class dataStore extends Store{ | ||
constructor(){ | ||
super(); | ||
this.todo = this.get('todo')||[]; | ||
} | ||
saveTodo(){ | ||
this.set('todo',this.todo); | ||
return this; | ||
} | ||
getTodo(){ | ||
const items = this.get('todo')||[]; | ||
return items; | ||
} | ||
addTodo(item){ | ||
this.todo.push(item); | ||
return this.saveTodo(); | ||
} | ||
deleteTodo(itemToDelete){ | ||
this.todo = this.todo.filter(item=>item!==itemToDelete) | ||
return this.saveTodo(); | ||
} | ||
} | ||
|
||
module.exports=dataStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const Store = require('electron-store'); | ||
|
||
class positionStore extends Store{ | ||
constructor(){ | ||
super(); | ||
this.x = parseInt(this.get('x'))||0; | ||
this.y = parseInt(this.get('y'))||0; | ||
} | ||
savePos(x,y){ | ||
this.x = x; | ||
this.y = y; | ||
this.set('x',x); | ||
this.set('y',y); | ||
} | ||
} | ||
|
||
module.exports = positionStore; |
Oops, something went wrong.