refactor: fix durationInSeconds type (#3399)
* chore: fix durationInSeconds type * chore: type
This commit is contained in:
@@ -246,7 +246,7 @@ function AudioCover({
|
||||
}: {
|
||||
entryId: string
|
||||
src: string
|
||||
durationInSeconds?: number
|
||||
durationInSeconds?: number | string
|
||||
feedIcon: React.ReactNode
|
||||
}) {
|
||||
const isMobile = useMobile()
|
||||
@@ -254,13 +254,8 @@ function AudioCover({
|
||||
playerValue.src === src && playerValue.show ? playerValue.status : false,
|
||||
)
|
||||
|
||||
// durationInSeconds's format like 00:00:00 or 4000
|
||||
if (durationInSeconds && Number.isNaN(+durationInSeconds)) {
|
||||
// @ts-expect-error durationInSeconds is string
|
||||
durationInSeconds = formatTimeToSeconds(durationInSeconds)
|
||||
}
|
||||
|
||||
const estimatedMins = durationInSeconds && Math.floor(durationInSeconds / 60)
|
||||
const seconds = formatTimeToSeconds(durationInSeconds)
|
||||
const estimatedMins = seconds && Math.floor(seconds / 60)
|
||||
|
||||
const handleClickPlay = (e: React.MouseEvent<HTMLDivElement>) => {
|
||||
if (isMobile) e.stopPropagation()
|
||||
|
||||
@@ -68,11 +68,9 @@ export const EntryTitle = ({ entryId, compact }: EntryLinkProps) => {
|
||||
return
|
||||
}
|
||||
|
||||
let durationInSeconds = audioAttachment.duration_in_seconds
|
||||
|
||||
if (Number.isNaN(+durationInSeconds)) {
|
||||
// @ts-expect-error durationInSeconds is string
|
||||
durationInSeconds = formatTimeToSeconds(durationInSeconds)
|
||||
const durationInSeconds = formatTimeToSeconds(audioAttachment.duration_in_seconds)
|
||||
if (!durationInSeconds) {
|
||||
return
|
||||
}
|
||||
|
||||
return formatEstimatedMins(Math.floor(durationInSeconds / 60))
|
||||
|
||||
@@ -10,12 +10,7 @@ import { EntryInfoContext } from "../context"
|
||||
export const TimeStamp = (props: { time: string }) => {
|
||||
const { entryId } = useContext(EntryInfoContext)
|
||||
const entry = useEntry(entryId)
|
||||
let mediaDuration = entry?.entries.attachments?.[0]?.duration_in_seconds
|
||||
|
||||
if (mediaDuration && Number.isNaN(+mediaDuration)) {
|
||||
// @ts-expect-error mediaDuration is string
|
||||
mediaDuration = formatTimeToSeconds(mediaDuration)
|
||||
}
|
||||
const mediaDuration = formatTimeToSeconds(entry?.entries.attachments?.[0]?.duration_in_seconds)
|
||||
|
||||
const src = entry?.entries?.attachments?.[0]?.url
|
||||
if (!src) return <span>{props.time}</span>
|
||||
|
||||
@@ -49,7 +49,7 @@ export type MediaModel = {
|
||||
|
||||
export type AttachmentsModel = {
|
||||
url: string
|
||||
duration_in_seconds?: number
|
||||
duration_in_seconds?: number | string
|
||||
mime_type?: string
|
||||
size_in_bytes?: number
|
||||
title?: string
|
||||
|
||||
@@ -89,13 +89,7 @@ export function EntryNormalItem({ entryId, extraData }: { entryId: string; extra
|
||||
const isLoading = audioState === "loading"
|
||||
|
||||
const estimatedMins = useMemo(() => {
|
||||
let durationInSeconds = audio?.duration_in_seconds
|
||||
// durationInSeconds's format like 00:00:00 or 4000
|
||||
if (durationInSeconds && Number.isNaN(+durationInSeconds)) {
|
||||
// @ts-expect-error durationInSeconds is string
|
||||
durationInSeconds = formatTimeToSeconds(durationInSeconds)
|
||||
}
|
||||
|
||||
const durationInSeconds = formatTimeToSeconds(audio?.duration_in_seconds)
|
||||
return durationInSeconds && Math.floor(durationInSeconds / 60)
|
||||
}, [audio?.duration_in_seconds])
|
||||
|
||||
|
||||
+28
-28
@@ -1574,7 +1574,7 @@ type MediaModel = {
|
||||
};
|
||||
type AttachmentsModel = {
|
||||
url: string;
|
||||
duration_in_seconds?: number;
|
||||
duration_in_seconds?: number | string;
|
||||
mime_type?: string;
|
||||
size_in_bytes?: number;
|
||||
title?: string;
|
||||
@@ -2027,20 +2027,20 @@ declare const entries: drizzle_orm_pg_core.PgTableWithColumns<{
|
||||
}>;
|
||||
declare const attachmentsZodSchema: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
||||
url: z.ZodString;
|
||||
duration_in_seconds: z.ZodOptional<z.ZodNumber>;
|
||||
duration_in_seconds: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
||||
mime_type: z.ZodOptional<z.ZodString>;
|
||||
size_in_bytes: z.ZodOptional<z.ZodNumber>;
|
||||
title: z.ZodOptional<z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}, {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}>, "many">>>;
|
||||
@@ -2258,20 +2258,20 @@ declare const entriesOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
|
||||
}, "media" | "attachments" | "extra">, {
|
||||
attachments: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
||||
url: z.ZodString;
|
||||
duration_in_seconds: z.ZodOptional<z.ZodNumber>;
|
||||
duration_in_seconds: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
||||
mime_type: z.ZodOptional<z.ZodString>;
|
||||
size_in_bytes: z.ZodOptional<z.ZodNumber>;
|
||||
title: z.ZodOptional<z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}, {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}>, "many">>>;
|
||||
@@ -2350,7 +2350,7 @@ declare const entriesOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -2387,7 +2387,7 @@ declare const entriesOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -3495,20 +3495,20 @@ declare const inboxesEntriesOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<
|
||||
}, "media" | "attachments" | "extra">, {
|
||||
attachments: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
||||
url: z.ZodString;
|
||||
duration_in_seconds: z.ZodOptional<z.ZodNumber>;
|
||||
duration_in_seconds: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
||||
mime_type: z.ZodOptional<z.ZodString>;
|
||||
size_in_bytes: z.ZodOptional<z.ZodNumber>;
|
||||
title: z.ZodOptional<z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}, {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}>, "many">>>;
|
||||
@@ -3588,7 +3588,7 @@ declare const inboxesEntriesOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -3626,7 +3626,7 @@ declare const inboxesEntriesOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -3804,20 +3804,20 @@ declare const inboxesEntriesInsertOpenAPISchema: z.ZodObject<z.objectUtil.extend
|
||||
}, "id" | "media" | "attachments" | "extra" | "insertedAt" | "publishedAt" | "inboxHandle">, {
|
||||
attachments: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
||||
url: z.ZodString;
|
||||
duration_in_seconds: z.ZodOptional<z.ZodNumber>;
|
||||
duration_in_seconds: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
|
||||
mime_type: z.ZodOptional<z.ZodString>;
|
||||
size_in_bytes: z.ZodOptional<z.ZodNumber>;
|
||||
title: z.ZodOptional<z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}, {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}>, "many">>>;
|
||||
@@ -3892,7 +3892,7 @@ declare const inboxesEntriesInsertOpenAPISchema: z.ZodObject<z.objectUtil.extend
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -3927,7 +3927,7 @@ declare const inboxesEntriesInsertOpenAPISchema: z.ZodObject<z.objectUtil.extend
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -14987,7 +14987,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -15197,7 +15197,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -15292,7 +15292,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -15449,7 +15449,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -15556,7 +15556,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -15655,7 +15655,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -15789,7 +15789,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -16817,7 +16817,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
@@ -17291,7 +17291,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
||||
attachments?: {
|
||||
url: string;
|
||||
title?: string | undefined;
|
||||
duration_in_seconds?: number | undefined;
|
||||
duration_in_seconds?: string | number | undefined;
|
||||
mime_type?: string | undefined;
|
||||
size_in_bytes?: number | undefined;
|
||||
}[] | null | undefined;
|
||||
|
||||
@@ -321,7 +321,11 @@ export function transformShortcut(shortcut: string, platform: OS = getOS()): str
|
||||
}
|
||||
|
||||
// time like 1:30:00
|
||||
export const formatTimeToSeconds = (time: string) => {
|
||||
export const formatTimeToSeconds = (time?: string | number) => {
|
||||
if (typeof time === "number" || time === undefined) {
|
||||
return time
|
||||
}
|
||||
|
||||
const formats = ["h:mm:ss", "mm:ss", "m:ss"]
|
||||
|
||||
for (const format of formats) {
|
||||
|
||||
Reference in New Issue
Block a user