mirror of
https://github.com/jeffvli/feishin.git
synced 2026-07-23 02:46:40 +02:00
refactor item table props
This commit is contained in:
@@ -18,10 +18,15 @@ const DateColumnBase = (props: ItemTableListInnerColumn) => {
|
||||
const rowItem = props.getRowItem?.(props.rowIndex) ?? (props.data as any[])[props.rowIndex];
|
||||
const row: string | undefined = (rowItem as any)?.[props.columns[props.columnIndex].id];
|
||||
|
||||
if (typeof row === 'string' && row) {
|
||||
const formattedAbsolute = useMemo(
|
||||
() => (typeof row === 'string' && row ? formatDateAbsolute(row) : null),
|
||||
[row],
|
||||
);
|
||||
|
||||
if (formattedAbsolute) {
|
||||
return (
|
||||
<TableColumnTextContainer {...props}>
|
||||
<span>{formatDateAbsolute(row)}</span>
|
||||
<span>{formattedAbsolute}</span>
|
||||
</TableColumnTextContainer>
|
||||
);
|
||||
}
|
||||
@@ -63,6 +68,11 @@ const AbsoluteDateColumnBase = (props: ItemTableListInnerColumn) => {
|
||||
return null;
|
||||
}, [props.type, rowItem]);
|
||||
|
||||
const formattedIsoFallback = useMemo(
|
||||
() => (typeof row === 'string' && row ? formatPartialIsoDateUTC(row) : null),
|
||||
[row],
|
||||
);
|
||||
|
||||
if (props.type === TableColumn.RELEASE_DATE) {
|
||||
if (releaseDateContent) {
|
||||
return (
|
||||
@@ -72,10 +82,10 @@ const AbsoluteDateColumnBase = (props: ItemTableListInnerColumn) => {
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof row === 'string' && row) {
|
||||
if (formattedIsoFallback) {
|
||||
return (
|
||||
<TableColumnTextContainer {...props}>
|
||||
<span>{formatPartialIsoDateUTC(row)}</span>
|
||||
<span>{formattedIsoFallback}</span>
|
||||
</TableColumnTextContainer>
|
||||
);
|
||||
}
|
||||
@@ -96,10 +106,15 @@ const RelativeDateColumnBase = (props: ItemTableListInnerColumn) => {
|
||||
const rowItem = props.getRowItem?.(props.rowIndex) ?? (props.data as any[])[props.rowIndex];
|
||||
const row: string | undefined = (rowItem as any)?.[props.columns[props.columnIndex].id];
|
||||
|
||||
if (typeof row === 'string') {
|
||||
const formattedRelative = useMemo(() => {
|
||||
if (typeof row !== 'string') return null;
|
||||
return formatDateRelative(row);
|
||||
}, [row]);
|
||||
|
||||
if (formattedRelative !== null) {
|
||||
return (
|
||||
<TableColumnTextContainer {...props}>
|
||||
<span>{formatDateRelative(row)}</span>
|
||||
<span>{formattedRelative}</span>
|
||||
</TableColumnTextContainer>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import clsx from 'clsx';
|
||||
import { useMemo } from 'react';
|
||||
import { Link } from 'react-router';
|
||||
|
||||
import styles from './title-column.module.css';
|
||||
@@ -35,8 +36,12 @@ function DefaultTitleColumn(props: ItemTableListInnerColumn) {
|
||||
const rowItem = props.getRowItem?.(props.rowIndex) ?? (props.data as any[])[props.rowIndex];
|
||||
const row: string | undefined = rowItem?.[props.columns[props.columnIndex].id];
|
||||
|
||||
const path = useMemo(() => {
|
||||
if (typeof row !== 'string' || !rowItem || !(rowItem as any).id) return undefined;
|
||||
return getTitlePath(props.itemType, (rowItem as any).id as string);
|
||||
}, [props.itemType, row, rowItem]);
|
||||
|
||||
if (typeof row === 'string') {
|
||||
const path = getTitlePath(props.itemType, (rowItem as any).id as string);
|
||||
const item = rowItem as any;
|
||||
|
||||
const titleLinkProps = path
|
||||
@@ -80,8 +85,12 @@ function QueueSongTitleColumn(props: ItemTableListInnerColumn) {
|
||||
const song = rowItem as QueueSong;
|
||||
const isActive = useIsActiveRow(song?.id, song?._uniqueId);
|
||||
|
||||
const path = useMemo(() => {
|
||||
if (typeof row !== 'string' || !rowItem || !(rowItem as any).id) return undefined;
|
||||
return getTitlePath(props.itemType, (rowItem as any).id as string);
|
||||
}, [props.itemType, row, rowItem]);
|
||||
|
||||
if (typeof row === 'string') {
|
||||
const path = getTitlePath(props.itemType, (rowItem as any).id as string);
|
||||
const item = rowItem as any;
|
||||
|
||||
const titleLinkProps = path
|
||||
|
||||
Reference in New Issue
Block a user