aboutsummaryrefslogtreecommitdiff
path: root/src/lib/AniList
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-12-29 20:50:58 -0800
committerFuwn <[email protected]>2023-12-29 20:50:58 -0800
commit7e4169ced2c6d55e25a54fad6d8be74ac733105b (patch)
tree851f9129199dbf950c2a68e7f470eece8ed7764c /src/lib/AniList
parentfeat(html): reorder title (diff)
downloaddue.moe-7e4169ced2c6d55e25a54fad6d8be74ac733105b.tar.xz
due.moe-7e4169ced2c6d55e25a54fad6d8be74ac733105b.zip
refactor(activity): prep for next year
Diffstat (limited to 'src/lib/AniList')
-rw-r--r--src/lib/AniList/activity.ts30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/lib/AniList/activity.ts b/src/lib/AniList/activity.ts
index 2a61b2dd..d3574aa2 100644
--- a/src/lib/AniList/activity.ts
+++ b/src/lib/AniList/activity.ts
@@ -8,13 +8,16 @@ export interface ActivityHistoryEntry {
export const fillMissingDays = (
inputActivities: ActivityHistoryEntry[],
- startOfYear = false
+ startOfYear = false,
+ year = new Date().getFullYear()
): ActivityHistoryEntry[] => {
+ const yearDate = new Date(year, 0, 0);
+
if (inputActivities.length === 0)
return startOfYear
? fillDateRange(
- new Date(new Date().getUTCFullYear(), 0, 1),
- new Date(new Date().getUTCFullYear() + 1, 0, 1)
+ new Date(yearDate.getUTCFullYear(), 0, 1),
+ new Date(yearDate.getUTCFullYear() + 1, 0, 1)
)
: [];
@@ -25,7 +28,7 @@ export const fillMissingDays = (
return fillDateRange(
startOfYear
- ? new Date(new Date().getUTCFullYear(), 0, 1)
+ ? new Date(yearDate.getUTCFullYear(), 0, 1)
: new Date(sortedActivities[0].date * 1000),
endDate,
sortedActivities
@@ -108,7 +111,8 @@ export interface ActivitiesPage {
const activitiesPage = async (
page: number,
anilistAuthorisation: AniListAuthorisation,
- userIdentity: UserIdentity
+ userIdentity: UserIdentity,
+ year = new Date().getFullYear()
): Promise<ActivitiesPage> =>
await (
await fetch('https://graphql.anilist.co', {
@@ -123,10 +127,8 @@ const activitiesPage = async (
Page(page: ${page}) {
pageInfo { hasNextPage }
activities(userId: ${userIdentity.id}, createdAt_greater: ${Math.floor(
- new Date(new Date().getFullYear(), 0, 1).getTime() / 1000
- )}, createdAt_lesser: ${Math.floor(
- new Date(new Date().getFullYear(), 6, 1).getTime() / 1000
- )}) {
+ new Date(year, 0, 1).getTime() / 1000
+ )}, createdAt_lesser: ${Math.floor(new Date(year, 6, 1).getTime() / 1000)}) {
... on TextActivity { createdAt }
... on ListActivity { createdAt }
... on MessageActivity { createdAt }
@@ -139,7 +141,8 @@ const activitiesPage = async (
export const fullActivityHistory = async (
anilistAuthorisation: AniListAuthorisation,
- userIdentity: UserIdentity
+ userIdentity: UserIdentity,
+ year = new Date().getFullYear()
): Promise<ActivityHistoryEntry[]> => {
const activities = [];
let page = 1;
@@ -148,7 +151,7 @@ export const fullActivityHistory = async (
if (currentDatabasePage) currentPage = currentDatabasePage.data;
else {
- currentPage = await activitiesPage(page, anilistAuthorisation, userIdentity);
+ currentPage = await activitiesPage(page, anilistAuthorisation, userIdentity, year);
database.activities.add({
page,
data: currentPage
@@ -165,7 +168,7 @@ export const fullActivityHistory = async (
if (currentDatabasePage) currentPage = currentDatabasePage.data;
else {
- currentPage = await activitiesPage(page, anilistAuthorisation, userIdentity);
+ currentPage = await activitiesPage(page, anilistAuthorisation, userIdentity, year);
database.activities.add({
page,
data: currentPage
@@ -202,8 +205,7 @@ export const fullActivityHistory = async (
);
fullLocalActivityHistory = fullLocalActivityHistory.filter(
- (activityHistoryEntry) =>
- new Date(activityHistoryEntry.date * 1000).getFullYear() === new Date().getFullYear()
+ (activityHistoryEntry) => new Date(activityHistoryEntry.date * 1000).getFullYear() === year
);
return fullLocalActivityHistory;