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

Moved Manga chapters over to Decimals for fractional releases #1002

Merged
merged 9 commits into from
Sep 4, 2024
2 changes: 1 addition & 1 deletion apps/frontend/app/lib/state/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type UpdateProgressData = {
showEpisodeNumber?: number | null;
podcastEpisodeNumber?: number | null;
animeEpisodeNumber?: number | null;
mangaChapterNumber?: number | null;
mangaChapterNumber?: string | null;
mangaVolumeNumber?: number | null;
};

Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/app/lib/utilities.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const emptyNumberString = z

const emptyDecimalString = z
.any()
.transform((v) => (!v ? undefined : Number.parseFloat(v)))
.transform((v) => (!v ? undefined : Number.parseFloat(v).toString()))
.nullable();

export const MetadataIdSchema = z.object({ metadataId: z.string() });
Expand Down
19 changes: 10 additions & 9 deletions apps/frontend/app/routes/_dashboard.media.item.$id._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
changeCase,
formatDateToNaiveDate,
humanizeDuration,
isInteger,
isNumber,
isString,
processSubmission,
Expand Down Expand Up @@ -1353,11 +1354,6 @@ const HistoryItem = (props: { history: History; index: number }) => {
e.episodeNumber === props.history.showExtraInformation?.episode,
)
: null;
const isNumberOrDecimalString = (value: unknown): boolean =>
isNumber(value) ||
(isString(value) &&
!Number.isNaN(Number.parseFloat(value)) &&
Number.isFinite(Number(value)));
const displayShowExtraInformation = showExtraInformation
? `S${props.history.showExtraInformation?.season}-E${props.history.showExtraInformation?.episode}: ${showExtraInformation.name}`
: null;
Expand All @@ -1377,10 +1373,15 @@ const HistoryItem = (props: { history: History; index: number }) => {
const displayMangaExtraInformation = (() => {
const { chapter, volume } = props.history.mangaExtraInformation || {};

if (isNumberOrDecimalString(chapter)) {
const chapterNum = Number.parseFloat(chapter);
const isWholeNumber = chapterNum % 1 === 0;
return `CH-${isWholeNumber ? Math.floor(chapterNum) : chapterNum}`;
if (chapter != null) {
const chapterNum = isString(chapter)
? Number.parseFloat(chapter)
: chapter;

if (!Number.isNaN(chapterNum)) {
const isWholeNumber = isInteger(chapterNum);
return `CH-${isWholeNumber ? Math.floor(chapterNum) : chapterNum}`;
}
}

if (isNumber(volume)) return `VOL-${volume}`;
Expand Down
12 changes: 7 additions & 5 deletions apps/frontend/app/routes/_dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -897,12 +897,12 @@ const MetadataInProgressUpdateForm = ({
</Text>
<Flex align="center" gap="xs">
<NumberInput
defaultValue={((total || 1) * (value || 1)) / 100}
defaultValue={((Number(total) || 1) * (value || 1)) / 100}
onChange={(v) => {
const value = (Number(v) / (total || 1)) * 100;
const value = (Number(v) / (Number(total) || 1)) * 100;
setValue(value);
}}
max={total}
max={Number(total)}
min={0}
step={1}
hideControls
Expand Down Expand Up @@ -999,7 +999,8 @@ const NewProgressUpdateForm = ({
onChange={(e) => {
setMetadataToUpdate(
produce(metadataToUpdate, (draft) => {
draft.mangaChapterNumber = Number(e);
draft.mangaChapterNumber =
e === "" ? undefined : Number(e).toString();
}),
);
}}
Expand All @@ -1014,7 +1015,8 @@ const NewProgressUpdateForm = ({
onChange={(e) => {
setMetadataToUpdate(
produce(metadataToUpdate, (draft) => {
draft.mangaVolumeNumber = Number(e);
draft.mangaVolumeNumber =
e === "" ? undefined : Number(e);
}),
);
}}
Expand Down
14 changes: 11 additions & 3 deletions apps/frontend/app/routes/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,15 @@ export const action = unstable_defineAction(async ({ request }) => {
}
}
if (submission.metadataLot === MediaLot.Manga) {
const isValidNumber = (value: unknown): boolean => {
const num = Number(value);
return !Number.isNaN(num) && Number.isFinite(num);
};

if (
(isNumber(submission.mangaChapterNumber) &&
(isValidNumber(submission.mangaChapterNumber) &&
isNumber(submission.mangaVolumeNumber)) ||
(!isNumber(submission.mangaChapterNumber) &&
(!isValidNumber(submission.mangaChapterNumber) &&
!isNumber(submission.mangaVolumeNumber))
)
throw Response.json({
Expand Down Expand Up @@ -308,7 +313,10 @@ export const action = unstable_defineAction(async ({ request }) => {

for (let i = 1; i < targetChapter; i++) {
if (!markedChapters.has(i)) {
updates.push({ ...variables, mangaChapterNumber: i });
updates.push({
...variables,
mangaChapterNumber: i.toString(),
});
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions libs/ts-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import groupBy from "lodash/groupBy";
import isBoolean from "lodash/isBoolean";
import isEmpty from "lodash/isEmpty";
import isEqual from "lodash/isEqual";
import isInteger from "lodash/isInteger";
IgnisDa marked this conversation as resolved.
Show resolved Hide resolved
import isNumber from "lodash/isNumber";
import isString from "lodash/isString";
import mapValues from "lodash/mapValues";
Expand Down Expand Up @@ -98,6 +99,7 @@ export {
isBoolean,
isEmpty,
isEqual,
isInteger,
isNumber,
isString,
mapValues,
Expand Down