-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added list of all events marked as complete
- Added list of all events marked as complete - Remove debugging `console.log`s - Refactored marking complete/incomplete functions
- Loading branch information
Showing
8 changed files
with
168 additions
and
62 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
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
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
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,109 @@ | ||
import { getCheckedCourses } from "./getCheckedCourses"; | ||
import { markIncompleteOnclick } from "./markTodos"; | ||
import { getCheckedTodos } from "./storage"; | ||
import { Todo } from "./types"; | ||
|
||
export async function displayCheckedTodos() { | ||
|
||
// Get checked courses | ||
const courseList: number[] = getCheckedCourses(); | ||
|
||
// Get all checked assignments | ||
const checkedTodos: Todo[] = getCheckedTodos(courseList); | ||
checkedTodos.reverse(); | ||
|
||
// Remove existing checked todos section if it exists | ||
const existingSection = document.querySelector('#checked-todos-section'); | ||
existingSection?.remove(); | ||
|
||
// Main div for checked todos | ||
const rsSection = document.createElement('div'); | ||
rsSection.classList.add('rs-section'); | ||
rsSection.id = 'checked-todos-section'; | ||
|
||
// Header | ||
const h2 = document.createElement('h2'); | ||
h2.tabIndex = -1; | ||
|
||
// Header button | ||
const span = document.createElement('span'); | ||
span.role = 'button'; | ||
span.id = 'checked-todos-button'; | ||
span.classList.add('element_toggler'); | ||
span.setAttribute('aria-controls', 'checked-todos'); | ||
span.setAttribute('aria-expanded', 'true'); | ||
span.setAttribute('aria-label', 'Undated items toggle list visibility'); | ||
span.tabIndex = 0; | ||
|
||
// Header button icon | ||
const i = document.createElement('i'); | ||
i.classList.add('auto_rotate'); | ||
i.classList.add('icon-mini-arrow-down'); | ||
|
||
span.appendChild(i); | ||
span.appendChild(document.createTextNode(' Canvas Strikethrough Checked')); | ||
|
||
h2.appendChild(span); | ||
|
||
// List of checked todos | ||
const div = document.createElement('div'); | ||
div.id = 'checked-todos'; | ||
div.style.display = 'block'; | ||
div.style.opacity = '1'; | ||
div.classList.add('ui-droppable'); | ||
|
||
const ul = document.createElement('ul'); | ||
ul.style.listStyleType = 'none'; | ||
ul.style.padding = '0'; | ||
ul.style.margin = '0'; | ||
ul.id = 'checked-todos-list'; | ||
|
||
checkedTodos.forEach((todo, index) => { | ||
|
||
const event = document.createElement('div'); | ||
event.classList.add('checked-todo'); | ||
event.classList.add('event'); | ||
event.classList.add(`group_course_${todo.courseId}`); | ||
event.id = `checked-todo-${index}`; | ||
event.style.borderRadius = '3px'; | ||
event.style.marginBottom = '3px'; | ||
event.style.padding = '3px'; | ||
event.style.color = 'white'; | ||
event.setAttribute('data-course-id', `${todo.courseId}`); | ||
event.setAttribute('data-todo-id', `${todo.id}`); | ||
|
||
const spanInner = document.createElement('a'); | ||
spanInner.innerHTML = todo.name.length > 25 ? todo.name.substring(0, 25) + '...' : todo.name; | ||
spanInner.classList.add('icon-calendar-month'); | ||
spanInner.style.color = 'white'; | ||
spanInner.style.textDecoration = 'none'; | ||
spanInner.style.cursor = 'pointer'; | ||
|
||
const markAsIncompleteButton = document.createElement('button'); | ||
markAsIncompleteButton.classList.add('Button'); | ||
markAsIncompleteButton.classList.add('Button--link'); | ||
markAsIncompleteButton.innerText = 'Mark as incomplete'; | ||
markAsIncompleteButton.style.padding = '5px'; | ||
|
||
markAsIncompleteButton.onclick = () => { | ||
markIncompleteOnclick(todo.courseId, todo, markAsIncompleteButton, true); | ||
|
||
// Remove checked todo from list | ||
const checkedTodo = document.querySelector(`#checked-todo-${index}`); | ||
checkedTodo?.remove(); | ||
}; | ||
|
||
event.appendChild(spanInner); | ||
event.appendChild(document.createElement('br')); | ||
event.appendChild(markAsIncompleteButton); | ||
ul.appendChild(event); | ||
}); | ||
|
||
div.appendChild(ul); | ||
|
||
rsSection.appendChild(h2); | ||
rsSection.appendChild(div); | ||
|
||
const main = document.querySelector('#right-side'); | ||
main?.appendChild(rsSection); | ||
} |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
// Get the course ID for the current grade page | ||
export function getCheckedCourses(): number[] { | ||
|
||
|
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,51 @@ | ||
import { displayCheckedTodos } from "./displayCheckedTodos"; | ||
import { getCalendarEvents } from "./getCalendarEvents"; | ||
import { addCheckedTodo, removeCheckedTodo } from "./storage"; | ||
import { CalendarEvent, Todo } from "./types"; | ||
import { checkEvent, uncheckEvent } from "./updateCalendarEvent"; | ||
|
||
export function markIncompleteOnclick(courseId: number, todo: Todo, checkButton: HTMLButtonElement, updateCalendar: boolean = false) { | ||
// Remove checked assignment | ||
removeCheckedTodo(todo.id); | ||
checkButton.innerHTML = 'Mark as complete'; | ||
|
||
// Uncheck event on calendar if updateCalendar is true | ||
if (updateCalendar) { | ||
const calendarEvents: CalendarEvent[] = getCalendarEvents(); | ||
|
||
calendarEvents.forEach((event: CalendarEvent) => { | ||
const { name, element } = event; | ||
|
||
// If assignment is checked | ||
if (name === todo.name) { | ||
uncheckEvent(element); | ||
displayCheckedTodos(); | ||
} | ||
}); | ||
} | ||
|
||
checkButton.onclick = () => { markCompleteOnclick(courseId, todo, checkButton, updateCalendar) }; | ||
} | ||
|
||
export function markCompleteOnclick(courseId: number, todo: Todo, checkButton: HTMLButtonElement, updateCalendar: boolean = false) { | ||
// Add checked assignment | ||
addCheckedTodo(todo) | ||
checkButton.innerHTML = 'Mark as incomplete'; | ||
|
||
// Check event on calendar if updateCalendar is true | ||
if (updateCalendar) { | ||
const calendarEvents: CalendarEvent[] = getCalendarEvents(); | ||
|
||
calendarEvents.forEach((event: CalendarEvent) => { | ||
const { name, element } = event; | ||
|
||
// If assignment is checked | ||
if (name === todo.name) { | ||
checkEvent(element); | ||
displayCheckedTodos(); | ||
} | ||
}); | ||
} | ||
|
||
checkButton.onclick = () => { markIncompleteOnclick(courseId, todo, checkButton, updateCalendar) }; | ||
} |
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
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 |
---|---|---|
@@ -1,11 +1,9 @@ | ||
// Check an event | ||
export async function checkEvent(event: Element) { | ||
|
||
event.querySelector('.fc-title')?.classList.add('calendar__event--completed'); | ||
} | ||
|
||
// Uncheck an event | ||
export async function uncheckEvent(event: Element) { | ||
|
||
event.querySelector('.fc-title')?.classList.remove('calendar__event--completed'); | ||
} |