Skip to content

Commit

Permalink
Merge pull request #73 from acmauth/consistencyTweaks
Browse files Browse the repository at this point in the history
Integrated grade dismiss undo
  • Loading branch information
neron-png authored Feb 28, 2024
2 parents 3892c6d + 4f37bb2 commit 700a216
Showing 1 changed file with 57 additions and 3 deletions.
60 changes: 57 additions & 3 deletions src/lib/components/recentGrades/recentGrades.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@
import { onMount } from "svelte";
import { universisGet } from "$lib/dataService";
import GradeCard from "$components/recentGrades/recentGradesCard.svelte";
import { dismissedGrades } from "$components/recentGrades/dismissedGrades"
;
import { dismissedGrades } from "$components/recentGrades/dismissedGrades";
import { refresh } from "ionicons/icons";
let examPeriod = [];
/**
* @type {any[]}
*/
let recentGrades = [];
/**
* @type {any[]}
*/
let allRecentGrades = []; //used to bring back recent grades with restore button
/**
* @type {string | any[]}
*/
let grades = [];
/**
* @type {any[]}
*/
let recentlyDismissedGrades = [];
// Subscribe to changes in dismissedGrades
const unsubscribe = dismissedGrades.subscribe(value => {
Expand All @@ -18,9 +32,13 @@
// Adding the grade from the deleted cards
function addToDismissedGrades(id){
dismissedGrades.update(ids => [...ids, id]);
recentlyDismissedGrades = [...recentlyDismissedGrades, id];
}
function removeFromDismissedGrades(id){
dismissedGrades.update(grades => grades.filter(grade => grade !== id));
}
function emptyDismissedGrades(){
dismissedGrades.update(grades => grades.filter(grade => false));
}
Expand Down Expand Up @@ -62,7 +80,7 @@
// getting recent grades from the previous period
recentGrades = (await universisGet('students/me/grades?$filter=courseExam/year eq ' + lastYear + ' and courseExam/examPeriod eq ' + lastPeriod + '&$expand=status,course($expand=gradeScale,locale),courseClass($expand=instructors($expand=instructor($select=InstructorSummary))),courseExam($expand=examPeriod,year)&$top=-1&$count=false')).value;
allRecentGrades = [...recentGrades];
}
// removing the grades that are already deleted
Expand All @@ -82,9 +100,27 @@
addToDismissedGrades(examId);
}
function restoreDeletedCard(){
let id = recentlyDismissedGrades[recentlyDismissedGrades.length - 1];
recentlyDismissedGrades = recentlyDismissedGrades.slice(0, -1);
removeFromDismissedGrades(id);
for (const recentGrade of allRecentGrades){
if (id === recentGrade.courseExam.id){
// recentGrades.push(recentGrade);
recentGrades = [...recentGrades, recentGrade];
console.log(recentGrades);
console.log(allRecentGrades);
}
}
// if (deletedCards.length === 0){
// showRestore = false;
// }
}
</script>

<div class="recentGrades ion-padding">

{#if recentGrades.length === 0}
<ion-card>
<ion-card-content>
Expand All @@ -95,6 +131,13 @@
{#each recentGrades as recentGrade }
<GradeCard subject = {recentGrade} on:delete-card={deleteCard}/>
{/each}

<div class="button-container">
{#if recentlyDismissedGrades.length > 0}
<ion-button class="undoButton ion-padding" on:click={restoreDeletedCard} aria-hidden><ion-icon icon={refresh}></ion-icon></ion-button>
{/if}
</div>

</div>

<style>
Expand All @@ -103,6 +146,17 @@
flex-direction: column;
gap: 0.5rem;
}
.button-container {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 999;
}
.undoButton {
--border-radius: 1rem;
--box-shadow: var(--shadow-short-md);
}
</style>


Expand Down

0 comments on commit 700a216

Please sign in to comment.