-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
93 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20.11.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,4 +82,3 @@ const title = data | |
) | ||
} | ||
</Layout> | ||
../../../util/comicvine.types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,3 @@ try { | |
) | ||
} | ||
</Layout> | ||
|
||
<style></style> | ||
../util/kv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,32 @@ | ||
import { persistentAtom } from "@nanostores/persistent"; | ||
import { atom } from "nanostores"; | ||
export type Sort = "asc" | "desc"; | ||
|
||
export const $sort = persistentAtom<Sort>("sortIssues", "asc"); | ||
function getSortfromURL() { | ||
if (typeof document === "undefined") { | ||
return "desc"; | ||
} | ||
const url = new URL(document.location.href); | ||
const sort = url.searchParams.get("sort"); | ||
|
||
if (sort === "asc") { | ||
return "asc"; | ||
} | ||
return "desc"; | ||
} | ||
|
||
function setSortInURL(sort: Sort) { | ||
const url = new URL(document.location.href); | ||
url.searchParams.set("sort", sort); | ||
history.pushState({}, "", url.href); | ||
} | ||
|
||
export const $sort = atom<Sort>(getSortfromURL()); | ||
|
||
export function toggleSort(sort: Sort) { | ||
if (sort === "asc") { | ||
$sort.set("desc"); | ||
} else { | ||
$sort.set("asc"); | ||
} | ||
setSortInURL($sort.get()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { Sort } from "../stores/sort.store"; | ||
import type { ShortIssue } from "./comicvine.types"; | ||
|
||
export function clampIssuesPerPage({ | ||
issuesPerPage, | ||
currentPage, | ||
issueList, | ||
sortDirection, | ||
}: { | ||
issuesPerPage: number; | ||
currentPage: number; | ||
issueList: ShortIssue[]; | ||
sortDirection: Sort; | ||
}) { | ||
// sort the issues by issue number | ||
if (sortDirection === "desc") { | ||
issueList.sort( | ||
(a, b) => parseInt(b.issue_number) - parseInt(a.issue_number) | ||
); | ||
} else { | ||
issueList.sort( | ||
(a, b) => parseInt(a.issue_number) - parseInt(b.issue_number) | ||
); | ||
} | ||
const trimmedList = issueList.slice( | ||
(currentPage - 1) * issuesPerPage, | ||
currentPage * issuesPerPage | ||
); | ||
|
||
return trimmedList; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters