diff --git a/public/scripts/extensions/objective/index.js b/public/scripts/extensions/objective/index.js
index 8c144cf8c..ec09ed4f6 100644
--- a/public/scripts/extensions/objective/index.js
+++ b/public/scripts/extensions/objective/index.js
@@ -61,7 +61,7 @@ async function generateQuietPrompt(quiet_prompt) {
// Accepts optional position. Defaults to adding to end of list.
function addTask(description, position = null) {
- position = position ? position != null : position = globalTasks.length
+ position = position != null ? position: position = globalTasks.length
globalTasks.splice(position, 0, {
"description": description,
"completed": false
@@ -78,19 +78,24 @@ function getTask(index = null, taskDescription = null) {
task = globalObjective[index]
} else if (taskDescription != null) {
task = globalTasks.find(task => {
- return true ? task.description == description : false
+ return task.description == description ? true: false
})
}
return task
}
+function deleteTask(index){
+ globalTasks.splice(index, 1)
+ setCurrentTask()
+ updateUiTaskList()
+}
+
// Complete the current task, setting next task to next incomplete task
function completeTask(task) {
task.completed = true
console.info(`Task successfully completed: ${JSON.stringify(task)}`)
setCurrentTask()
updateUiTaskList()
- saveState()
}
// Call Quiet Generate to create task list using character context, then convert to tasks. Should not be called much.
@@ -227,9 +232,11 @@ function addUiTask(taskIndex, taskComplete, taskDescription) {
${taskIndex}
${taskDescription}
+
+
`;
-
+
// Add the filled out template
$('#objective-tasks').append(template);
@@ -244,17 +251,40 @@ function addUiTask(taskIndex, taskComplete, taskDescription) {
const index = Number(event.target.id.split('-').pop());
globalTasks[index].description = event.target.textContent;
});
+ $(`#objective-task-delete-${taskIndex}`).on('click', event => {
+ const index = Number(event.target.id.split('-').pop());
+ deleteTask(index)
+ });
+ $(`#objective-task-add-${taskIndex}`).on('click', event => {
+ const index = Number(event.target.id.split('-').pop()) + 1;
+ addTask("", index)
+ setCurrentTask()
+ updateUiTaskList()
+ });
}
// Populate UI task list
function updateUiTaskList() {
$('#objective-tasks').empty()
- for (const index in globalTasks) {
- addUiTask(
- index,
- globalTasks[index].completed,
- globalTasks[index].description
- )
+ // Show tasks if there are any
+ if (globalTasks.length > 0){
+ for (const index in globalTasks) {
+ addUiTask(
+ index,
+ globalTasks[index].completed,
+ globalTasks[index].description
+ )
+ }
+ } else {
+ // Show button to add tasks if there are none
+ $('#objective-tasks').append(`
+
+ `)
+ $("#objective-task-add-first").on('click', () => {
+ addTask("")
+ setCurrentTask()
+ updateUiTaskList()
+ })
}
}
diff --git a/public/scripts/extensions/objective/style.css b/public/scripts/extensions/objective/style.css
index 3f6f4a8fd..90613f467 100644
--- a/public/scripts/extensions/objective/style.css
+++ b/public/scripts/extensions/objective/style.css
@@ -14,3 +14,23 @@
.objective_block_control label {
width: max-content;
}
+
+.objective-task-button {
+ margin: 0;
+ outline: none;
+ border: none;
+ cursor: pointer;
+ transition: 0.3s;
+ opacity: 0.7;
+ align-items: center;
+ justify-content: center;
+
+}
+
+.objective-task-button:hover {
+ opacity: 1;
+}
+
+[id^=objective-task-delete-] {
+ color: #da3f3f;
+}
\ No newline at end of file