Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete events feature #18

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,19 @@ function App() {
setCustomEvents((currentList) => [...currentList, newEvent]);
};
const removeEvent = (eventName, startTime, endTime) => {
const jsonObj = JSON.parse(localStorage.getItem(customKey)) || [];
const customEventList = JSON.parse(localStorage.getItem(customKey)) || [];

const newCustomList = [];
jsonObj.forEach((delEvent) => {
console.log(startTime, delEvent.title);

customEventList.forEach((event) => {

if (
delEvent.title === eventName
&& delEvent.start === startTime
&& delEvent.end === endTime
event.title === eventName
&& event.start === startTime
&& event.end === endTime
) {
return;
}
newCustomList.push(delEvent);
newCustomList.push(event);
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of the unnecessary console logs. Variables like jsonObj need to be changed to more meaningful names.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Variable names like delEvent can be improved. Especially because delEvent is actually the event which stays and is not being deleted!

A generic name for the function argument like event might suffice.


localStorage.setItem(customKey, JSON.stringify(newCustomList));
Expand Down
Empty file removed src/components/Notes.js
Empty file.
27 changes: 11 additions & 16 deletions src/pages/TimeTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ function TimeTable({ eventList, handleNewCustomEvent, handleDeleteEvent }) {
const [showAimsError, setShowAimsError] = useState(
localStorage.getItem('aimskey') === null,
);
const aimsCourse = JSON.parse(localStorage.getItem('aimskey')) || null

const muiTheme = useTheme();

let title = '';
let eventDate = null;
let startTime = null;
let endTime = null;
// let note = "";

const handleClickOpen = () => {
setOpen(true);
Expand Down Expand Up @@ -83,18 +83,20 @@ function TimeTable({ eventList, handleNewCustomEvent, handleDeleteEvent }) {

// deletes custom event on click
const handleDelete = (clickInfo) => {
console.log(clickInfo.event.start.toISOString());
if (
window.confirm(
`Are you sure you want to delete the event '${clickInfo.event.title}'`,
)
) {
clickInfo.event.remove();
handleDeleteEvent(

const aimsTitle = aimsCourse.identifiedCourses.find(course => course === clickInfo.event.title)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not going to work in the newer version of the extension, where the course title also includes the course name.

if (aimsTitle !== undefined){
window.alert('AIMS courses cannot be deleted.');
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation Error

if (window.confirm(`Are you sure you want to delete the event '${clickInfo.event.title}'`)){
clickInfo.event.remove()
handleDeleteEvent(
clickInfo.event.title,
clickInfo.event.start.toISOString(),
clickInfo.event.end.toISOString(),
);
}
}
};

Expand Down Expand Up @@ -235,13 +237,6 @@ function TimeTable({ eventList, handleNewCustomEvent, handleDeleteEvent }) {
shrink: true,
}}
/>
{/* <TextField
margin="dense"
id="notes"
label="Add note"
fullWidth
onChange={handleNoteChange}
/> */}
</DialogContent>
<DialogActions>
<Button
Expand Down