Skip to content

Commit

Permalink
Merge pull request #41 from beyenilmez/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
beyenilmez authored Feb 24, 2024
2 parents 3c4875b + 3b54409 commit a2925df
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 25 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gradeful",
"version": "1.2.0",
"version": "1.2.1",
"description": "A grade tracker to monitor your progress throughout your university education.",
"private": true,
"homepage": ".",
Expand Down Expand Up @@ -43,4 +43,4 @@
"url": "https://github.com/beyenilmez"
},
"license": "MIT"
}
}
5 changes: 4 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import LoadURLPopup from "./components/LoadURLPopup";
import Grid from "./components/Grid";
import { InactiveProvider } from "./components/InactiveContext";
import QucikStartWindow from "./components/QuickStartWindow";
import { useUniData } from "./components/UniContext";

document.body.className = 'bg-slate-250 dark:bg-slate-750 dark:text-slate-200 text-slate-800 slate';

function App() {
const [showSettings, setShowSettings] = useState(false);
const [showExportURLPopup, setShowExportURLPopup] = useState(false);

const {refresh} = useUniData();

return (
<React.Fragment>
<NavBar setShowSettings={setShowSettings} setShowExportURLPopup={setShowExportURLPopup} />
<InactiveProvider>
<Grid />
<Grid key={refresh} />
</InactiveProvider>
<SettingsWindow showSettingsPopup={showSettings} setShowSettingsPopup={setShowSettings} />
<ExportURLPopup showExportURLPopup={showExportURLPopup} setShowExportURLPopup={setShowExportURLPopup} />
Expand Down
6 changes: 1 addition & 5 deletions src/components/Course.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,10 @@ function CourseExport(props) {
// <--- Functions start --->

function addScore() {
const uni = new University(universityData);
const course = uni.getTermById(termIdRef.current).getCourseById(idRef.current);

const course = new Course(editData);
course.addScore(new Score());

setEditJSON({ ...editJSON, [idRef.current]: course });

setUniversityData(uni);
}

function deleteCourse() {
Expand Down
13 changes: 9 additions & 4 deletions src/components/Grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const sortableOptions = {
function Grid() {
const { setInactive } = useInactive();
const { setClassInactive } = useInactive();
const { universityData, setUniversityData, save } = useUniData();
const { universityData, setUniversityData, save, editJSON } = useUniData();

return (
<ReactSortable
Expand Down Expand Up @@ -73,9 +73,14 @@ function Grid() {
}}
{...sortableOptions}
>
{course.scores.map((score) => (
<Score key={score.id} id={score.id} courseId={course.id} termId={course.termId} name={score.name} percentage={score.percentage} score={score.score} />
))}
<React.Fragment>
{editJSON[course.id] === undefined && course.scores.map((score) => (
<Score key={score.id} id={score.id} courseId={course.id} termId={course.termId} name={score.name} percentage={score.percentage} score={score.score} />
))}
{editJSON[course.id] !== undefined && editJSON[course.id].scores && editJSON[course.id].scores.map((score) => (
<Score key={score.id} id={score.id} courseId={course.id} termId={course.termId} name={score.name} percentage={score.percentage} />
))}
</React.Fragment>
</ReactSortable>
</Course>
))}
Expand Down
14 changes: 8 additions & 6 deletions src/components/Score.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import { University, Course } from "../utils/Program";
import { Trash } from 'react-feather';
Expand Down Expand Up @@ -38,11 +38,13 @@ function ScoreExport(props) {
}

function updateScore() {
const uni = new University();
uni.load(universityData);
uni.getTermById(termIdRef.current).getCourseById(courseIdRef.current).getScoreById(idRef.current).score = scoreValue;
save();
setUniversityData(uni);
if (editData === undefined) {
const uni = new University();
uni.load(universityData);
uni.getTermById(termIdRef.current).getCourseById(courseIdRef.current).getScoreById(idRef.current).score = scoreValue;
save();
setUniversityData(uni);
}
}

// Effects
Expand Down
14 changes: 10 additions & 4 deletions src/components/SettingsWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,22 @@ function About() {
<div className='w-fit'>
v-{"1.2.0"}
</div>
<a
className='dark:text-sky-300 text-sky-300 underline w-fit'
href='https://github.com/beyenilmez/gradeful' target="_blank" rel="noreferrer">
Github
<a className='dark:text-sky-300 text-sky-300 underline w-fit cursor-pointer' onClick={() => {
localStorage.clear();
window.location.reload();
}} target="_blank">
Delete all data
</a>
<a
className='dark:text-sky-300 text-sky-300 underline w-fit'
href='./licenses.json' target="_blank">
View Licenses
</a>
<a
className='dark:text-sky-300 text-sky-300 underline w-fit'
href='https://github.com/beyenilmez/gradeful' target="_blank" rel="noreferrer">
Github
</a>
</div>
</div>
)
Expand Down
5 changes: 4 additions & 1 deletion src/components/UniContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const UniProvider = (props) => {

const [saveNextChange, setSaveNextChange] = useState(false);
const [reloadNextChange, setReloadNextChange] = useState(false);
const [refresh, setRefresh] = useState(0);

useEffect(() => {
if (saveNextChange) {
Expand All @@ -21,7 +22,9 @@ export const UniProvider = (props) => {
localStorage.setItem('university', JSON.stringify(uni));
setSaveNextChange(false);
if(reloadNextChange){
setReloadNextChange(false);
history.replaceState(null, null, window.location.href.split('?')[0]);
setRefresh(refresh + 1);
}
}
}, [universityData, saveNextChange]);
Expand All @@ -34,7 +37,7 @@ export const UniProvider = (props) => {
}

return (
<UniContext.Provider value={{ universityData, setUniversityData, editJSON, setEditJSON, save }}>
<UniContext.Provider value={{ universityData, setUniversityData, editJSON, setEditJSON, save, refresh }}>
{props.children}
</UniContext.Provider>
);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/Program.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class Course {
}

calcTotalPercentage() {
this.totalPercentage = this.scores.reduce((a, b) => a + Number((b.score === null || b.score === "" || b.score === undefined ? 0 : b.percentage)), 0);
this.totalPercentage = this.scores.reduce((a, b) => a + Number((b.score === null || b.score === "" || b.score === undefined || b.percentage === null || b.percentage === "" || b.percentage === undefined ? 0 : b.percentage)), 0);
this.inactive = this.totalPercentage === 0;
}

Expand All @@ -360,7 +360,7 @@ export class Course {
this.score = '';
return;
}
this.score =(this.scores.reduce((a, b) => a + Number((b.score === null || b.score === "" || b.score === undefined ? 0 : Number(b.score) * Number(b.percentage))), 0) / this.totalPercentage);
this.score =(this.scores.reduce((a, b) => a + Number((b.score === null || b.score === "" || b.score === undefined || b.percentage === null || b.percentage === "" || b.percentage === undefined ? 0 : Number(b.score) * Number(b.percentage))), 0) / this.totalPercentage);
}

calcGrade() {
Expand Down

0 comments on commit a2925df

Please sign in to comment.