diff --git a/.DS_Store b/.DS_Store index 390d2b9..7359e52 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/IMPORTANTTODO.md b/IMPORTANTTODO.md deleted file mode 100644 index bbb1033..0000000 --- a/IMPORTANTTODO.md +++ /dev/null @@ -1,8 +0,0 @@ -# IMPORTANT TODOS - -- add new page feature - -- add feature to set the lang and long of weather widget - -- add vanilla toast lib - diff --git a/TODO.md b/TODO.md index 4314591..ccc0b92 100644 --- a/TODO.md +++ b/TODO.md @@ -1,12 +1,5 @@ # TODO -- IMPORTANT: add feature to set the lang and long of weather widget - -- add simple adding from custom widgets - - add random notes widget - -- add function to save label in index.js file - -- clean up configureWidgets.js file \ No newline at end of file +- add vanilla toast lib diff --git a/src/index.html b/src/index.html index 139761c..e16eebe 100644 --- a/src/index.html +++ b/src/index.html @@ -17,9 +17,12 @@ - + + + + diff --git a/src/js/ButtonHandlers/addWidgetButton.js b/src/js/ButtonHandlers/addWidgetButton.js new file mode 100644 index 0000000..2971144 --- /dev/null +++ b/src/js/ButtonHandlers/addWidgetButton.js @@ -0,0 +1,21 @@ +import { addWidget } from "../configureWidgets.js"; + +const addButton = document.getElementById("addWidgetButton"); +const menu = document.querySelector(".widgetButtonsMenu"); + +addButton.addEventListener("click", function () { + if (menu.style.display === "none" || menu.style.display === "") { + menu.style.display = "block"; + } else { + menu.style.display = "none"; + } +}); + +document.addEventListener("click", function (event) { + if (!menu.contains(event.target) && event.target !== addButton) { + menu.style.display = "none"; + } else if (menu.contains(event.target) && event.target !== addButton) { + menu.style.display = "none"; + addWidget(event.target.getAttribute("data-widgetType")); + } +}); diff --git a/src/js/editButton.js b/src/js/ButtonHandlers/editButton.js similarity index 85% rename from src/js/editButton.js rename to src/js/ButtonHandlers/editButton.js index 2abf91b..509b0f8 100644 --- a/src/js/editButton.js +++ b/src/js/ButtonHandlers/editButton.js @@ -1,4 +1,4 @@ -import { widgets } from "./configureWidgets.js"; +import { widgets } from "../configureWidgets.js"; const editButton = document.getElementById("editButton") let editMode = false; diff --git a/src/js/Widgets/calendar.js b/src/js/Widgets/calendar.js index 727c96a..33ef7b9 100644 --- a/src/js/Widgets/calendar.js +++ b/src/js/Widgets/calendar.js @@ -185,6 +185,9 @@ export class CalendarWidget extends Widget { li.appendChild(date); ul.appendChild(li); + ul.addEventListener("click", (event) => { + + }) }); } diff --git a/src/js/Widgets/weather.js b/src/js/Widgets/weather.js index bc71203..0147d06 100644 --- a/src/js/Widgets/weather.js +++ b/src/js/Widgets/weather.js @@ -73,7 +73,7 @@ export class WeatherWidget extends Widget { const imgSrc = dayPath.querySelector("#weather-src"); imgSrc.src = `resources/weather-icons/${weatherPath}`; // set temperature - dayPath.querySelector(".temperature").textContent = temp; + dayPath.querySelector(".temperature").textContent = temp + "°"; // set location dayPath.querySelector(".location").textContent = this.uniqueWidgetData.loc; diff --git a/src/js/configureWidgets.js b/src/js/configureWidgets.js index 309f47d..31a4729 100644 --- a/src/js/configureWidgets.js +++ b/src/js/configureWidgets.js @@ -4,7 +4,10 @@ import { TextBox } from "./Widgets/textBox.js"; import { MediaWidget } from "./Widgets/media.js"; import { WeatherWidget } from "./Widgets/weather.js"; import { CalendarWidget } from "./Widgets/calendar.js"; + + import {currentProject, currentProjectPage} from "./manageOrder.js" +import { rePosWidgets } from "./rePosWidgets.js"; export let widgets = []; let widgetData = {}; @@ -60,7 +63,8 @@ const loadWidgetData = async () =>{ await restoreData() await loadPage() } -function addWidget(type){ + +export function addWidget(type){ const exampleDataExtended = {...exampleData, ...{type: type, page: currentProjectPage, project: currentProject}} spawnWidget(widgetData[type]["html"], {... widgetData[type]["uniqueWidgetData"]}, new Date().getTime(), type, {... exampleDataExtended}) } @@ -89,71 +93,4 @@ function spawnWidget(html, uniqueWidgetData, wId, wType, data){ } -addEventListener("beforeunload", (event) => { - for (let w of widgets){ - w.saveData() - } -}); - - - -function rePosWidgets(){ - let width = window.innerWidth - let height = window.innerHeight - for (let w of widgets) { - const anchorX = w.data.anchorX; - const anchorY = w.data.anchorY; - let newXPos; - let newYPos; - - // rePos x - if (anchorX[0] == "right") { - newXPos = width - parseInt(w.uniqueWidgetData.width) - parseInt(anchorX[1]); - } else if (anchorX[0] == "left") { - newXPos = parseInt(anchorX[1]); - } - - // rePos y - if (anchorY[0] == "bottom") { - newYPos = height - parseInt(w.uniqueWidgetData.height) - parseInt(anchorY[1]); - } else if (anchorY[0] == "top") { - newYPos = parseInt(anchorY[1]); - } - - - w.data.xPos = newXPos + "px"; - w.data.yPos = newYPos + "px"; - w.updatePos(); - } - -} -const addButton = document.getElementById("addWidgetButton"); -const menu = document.querySelector(".widgetButtonsMenu"); - -addButton.addEventListener("click", function() { - if (menu.style.display === "none" || menu.style.display === "") { - menu.style.display = "block"; - } else { - menu.style.display = "none"; - } -}); - -document.addEventListener("click", function(event) { - if (!menu.contains(event.target) && event.target !== addButton) { - menu.style.display = "none"; - }else if(menu.contains(event.target) && event.target !== addButton){ - menu.style.display = "none"; - addWidget(event.target.getAttribute("data-widgetType")) - } -}); - loadWidgetData(); - - - -window.electronAPI.onSavePage(() => { - for (let w of widgets){ - w.saveData() - } - console.log("Saved") - }); diff --git a/src/js/rePosWidgets.js b/src/js/rePosWidgets.js new file mode 100644 index 0000000..869affb --- /dev/null +++ b/src/js/rePosWidgets.js @@ -0,0 +1,32 @@ +import { widgets } from "./configureWidgets.js"; + +export function rePosWidgets(){ + let width = window.innerWidth + let height = window.innerHeight + for (let w of widgets) { + const anchorX = w.data.anchorX; + const anchorY = w.data.anchorY; + let newXPos; + let newYPos; + + // rePos x + if (anchorX[0] == "right") { + newXPos = width - parseInt(w.uniqueWidgetData.width) - parseInt(anchorX[1]); + } else if (anchorX[0] == "left") { + newXPos = parseInt(anchorX[1]); + } + + // rePos y + if (anchorY[0] == "bottom") { + newYPos = height - parseInt(w.uniqueWidgetData.height) - parseInt(anchorY[1]); + } else if (anchorY[0] == "top") { + newYPos = parseInt(anchorY[1]); + } + + + w.data.xPos = newXPos + "px"; + w.data.yPos = newYPos + "px"; + w.updatePos(); + } + +} \ No newline at end of file diff --git a/src/js/save.js b/src/js/save.js new file mode 100644 index 0000000..f54a8ab --- /dev/null +++ b/src/js/save.js @@ -0,0 +1,13 @@ +import { widgets } from "./configureWidgets.js"; + +window.electronAPI.onSavePage(() => { + for (let w of widgets) { + w.saveData(); + } +}); + +addEventListener("beforeunload", (event) => { + for (let w of widgets) { + w.saveData(); + } +}); diff --git a/src/js/widget.js b/src/js/widget.js index 859b213..5a99b71 100644 --- a/src/js/widget.js +++ b/src/js/widget.js @@ -1,5 +1,5 @@ import { getSettingsData, getTarget, handleWidgetSettingsMenu } from "./widgetSettingsMenu.js"; -import { editMode } from "./editButton.js"; +import { editMode } from "./ButtonHandlers/editButton.js"; const titleHtml = `