Skip to content

Commit

Permalink
Added comments for clarity and week label to history modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajit Khatri authored and Rajit Khatri committed Nov 12, 2024
1 parent d05c894 commit 68baa50
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/components/ListeningHistoryModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ListeningHistoryModal extends React.Component <{setModalIsOpen: (value: bo
}
}


async componentDidMount(): Promise<void> {
let newState = await getRecentlyPlayedTracksMetrics();
this.setState({
Expand All @@ -55,6 +56,33 @@ class ListeningHistoryModal extends React.Component <{setModalIsOpen: (value: bo
}}>
{"Listening History"}
</div>
<div style={{fontSize: "large",
marginLeft: "15px",
marginTop: "26px"
}}>
{"Week of "}
<span style={{fontWeight: "bolder"}}>
{function() {
let getDateRange = () => {
let weekStartDate = new Date(); // Date of the first day of the week
let day = weekStartDate.getDay() || 7; // Return 7 if day is Sunday

// If today is not a Monday, then rewind the
// date back to Monday
if (day != 1) {
weekStartDate.setHours(-24 * (day - 1));
}

// First Monday of the week and the current date
return weekStartDate;
}

let weekStartDate = getDateRange();

return `${weekStartDate.getMonth() + 1}/${weekStartDate.getDate()}`;
}()}
</span>
</div>
<img className={styles.playIcon} style={{marginLeft: "auto"}}
src={"https://img.icons8.com/?size=100&id=6483&format=png&color=FFFFFF"}
onClick={() => this.props.setModalIsOpen(false)}/>
Expand Down
7 changes: 5 additions & 2 deletions src/services/recentlyPlayedService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ async function getRecentlyPlayedTracksMetrics() : Promise<HistoricalMetrics | {}
after: "",
};
// Get the date of the first day of the week
let today = new Date();
let day = today.getDay() || 7;
let today = new Date();
let day = today.getDay() || 7; // Return 7 if day is Sunday

// If today is not a Monday, then rewind the
// date back to the previous Monday
if (day != 1) {
today.setHours(-24 * (day - 1));
}
Expand Down

0 comments on commit 68baa50

Please sign in to comment.