forked from Shinonome/dots-hyprland
sidebar todo
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import "root:/modules/common"
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import "root:/modules/common"
|
||||
pragma Singleton
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
pragma Singleton
|
||||
|
||||
import Quickshell;
|
||||
import Quickshell.Io;
|
||||
import Quickshell.Services.Pipewire;
|
||||
import Qt.labs.platform
|
||||
import QtQuick;
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
property var filePath: `${StandardPaths.standardLocations(StandardPaths.StateLocation)[0]}/user/todo.json`
|
||||
property var list: []
|
||||
|
||||
function addItem(item) {
|
||||
list.push(item)
|
||||
todoFileView.setText(JSON.stringify(root.list))
|
||||
}
|
||||
|
||||
function markDone(index) {
|
||||
if (index >= 0 && index < list.length) {
|
||||
list[index].done = true
|
||||
todoFileView.setText(JSON.stringify(root.list))
|
||||
}
|
||||
}
|
||||
|
||||
function deleteItem(index) {
|
||||
if (index >= 0 && index < list.length) {
|
||||
list.splice(index, 1)
|
||||
todoFileView.setText(JSON.stringify(root.list))
|
||||
}
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
todoFileView.reload()
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
refresh()
|
||||
}
|
||||
|
||||
FileView {
|
||||
id: todoFileView
|
||||
path: filePath
|
||||
onLoaded: {
|
||||
const fileContents = todoFileView.text()
|
||||
root.list = JSON.parse(fileContents)
|
||||
}
|
||||
onLoadFailed: (error) => {
|
||||
if(error == FileViewError.FileNotFound) {
|
||||
console.log("[To Do] File not found, creating new file.")
|
||||
root.list = []
|
||||
todoFileView.setText(JSON.stringify(root.list))
|
||||
} else {
|
||||
console.log("[To Do] Error loading file: " + error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user