Skip to content

Commit dbc3deb

Browse files
committed
work on upload bahaviour
1 parent 144b302 commit dbc3deb

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

my-app/src/views/Components/SideBarComponents/CourseTranscriptList.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { useState, useRef } from "react";
1+
import { useState, useRef, forwardRef } from "react";
22
import Tooltip from "./ToolTip";
33

44
export default function CourseTranscriptList(props) {
55
let local = [];
66
if (localStorage.getItem("completedCourses"))
77
local = JSON.parse(localStorage.getItem("completedCourses"));
8-
8+
9+
const [items, setItems] = useState(local);
10+
911
// eslint-disable-next-line no-unused-vars
1012
window.addEventListener("completedCourses changed", event => {
1113
if (localStorage.getItem("completedCourses"))
@@ -14,8 +16,6 @@ export default function CourseTranscriptList(props) {
1416
});
1517

1618

17-
const [items, setItems] = useState(local);
18-
1919
function removeItem(index) {
2020
var newItems = [];
2121
for (let i = 0; i < items.length; i++) {
@@ -31,6 +31,9 @@ export default function CourseTranscriptList(props) {
3131
localStorage.setItem("completedCourses", JSON.stringify(newitems));
3232
window.dispatchEvent(new Event("completedCourses changed"));
3333
props.reApplyFilter();
34+
if (props.checkboxRef && props.checkboxRef.current) {
35+
props.checkboxRef.current.click();
36+
}
3437
};
3538

3639

my-app/src/views/Components/SideBarComponents/UploadField.jsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useRef } from "react";
1+
import React, { useState, useRef, useEffect } from "react";
22
import CourseTranscriptList from './CourseTranscriptList';
33
import FilterEnableCheckbox from "./FilterEnableCheckbox";
44
//import * as scraper from '../../../../src/scripts/transcript-scraper/transcript-scraper.js';
@@ -13,10 +13,6 @@ export default function UploadField(props) {
1313

1414
const checkboxRef = useRef(null);
1515

16-
useState(() => {
17-
setfileUploaded(localStorage.getItem("completedCourses") != undefined)
18-
});
19-
2016
const handleDragOver = (event) => {
2117
event.preventDefault(); // Prevent default behavior (to allow drop)
2218
setIsDragging(true);
@@ -31,6 +27,8 @@ export default function UploadField(props) {
3127
setIsDragging(false);
3228
if (event.dataTransfer.files.length > 0) {
3329
props.handleFileChange({ target: { files: event.dataTransfer.files } });
30+
setfileUploaded(localStorage.getItem("completedCourses") != undefined);
31+
console.log(localStorage.getItem("completedCourses") != undefined);
3432
}
3533
};
3634

@@ -76,7 +74,14 @@ export default function UploadField(props) {
7674
<p className=" text-sm "><span className="font-semibold">Click to upload</span> or drag and drop</p>
7775
<p className="text-xs">KTH transcript of records in PDF format</p>
7876
</div>
79-
<input id="PDF-Scraper-Input" type="file" className="hidden" onChange={props.handleFileChange} />
77+
<input
78+
id="PDF-Scraper-Input"
79+
type="file"
80+
className="hidden"
81+
onChange={(event) => {
82+
props.handleFileChange(event);
83+
setfileUploaded(true);
84+
}} />
8085
</label>
8186
</div>
8287
<ButtonGroupField
@@ -94,6 +99,7 @@ export default function UploadField(props) {
9499
}`}>
95100
<CourseTranscriptList
96101
reApplyFilter={props.reApplyFilter}
102+
ref={checkboxRef}
97103
/>
98104
</div>
99105
</div>

0 commit comments

Comments
 (0)