fix
This commit is contained in:
parent
9fd88fae93
commit
61173c119a
|
|
@ -460,7 +460,6 @@ export const TableList: FC<TableListProp> = ({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode === "list") {
|
if (mode === "list") {
|
||||||
if (columns.length > 1) columns = columns.slice(0, 0 + 1);
|
if (columns.length > 1) columns = columns.slice(0, 0 + 1);
|
||||||
}
|
}
|
||||||
|
|
@ -519,7 +518,14 @@ export const TableList: FC<TableListProp> = ({
|
||||||
};
|
};
|
||||||
if (id_parent) load_args.paging = {};
|
if (id_parent) load_args.paging = {};
|
||||||
if (typeof on_load === "function") {
|
if (typeof on_load === "function") {
|
||||||
local.data = on_load({ ...load_args, mode: "query" }) as any;
|
let res = on_load({ ...load_args, mode: "query" }) as any;
|
||||||
|
if(typeof res === "object" && res instanceof Promise){
|
||||||
|
res.then((e) => {
|
||||||
|
local.data = e
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
local.data = e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
local.status = "ready";
|
local.status = "ready";
|
||||||
|
|
@ -709,7 +715,7 @@ export const TableList: FC<TableListProp> = ({
|
||||||
className="w-full h-full overflow-y-auto"
|
className="w-full h-full overflow-y-auto"
|
||||||
onScroll={local.paging.scroll}
|
onScroll={local.paging.scroll}
|
||||||
>
|
>
|
||||||
{data.map((e, idx) => {
|
{Array.isArray(data) ? data.map((e, idx) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="flex-grow"
|
className="flex-grow"
|
||||||
|
|
@ -729,7 +735,7 @@ export const TableList: FC<TableListProp> = ({
|
||||||
</PassProp>
|
</PassProp>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
}) : <>No Data</>}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ export const FormatValue: FC<{
|
||||||
name: string;
|
name: string;
|
||||||
gen_fields: string[];
|
gen_fields: string[];
|
||||||
tree_depth?: number;
|
tree_depth?: number;
|
||||||
mode?: "money" | "datetime";
|
mode?: "money" | "datetime" | "timeago";
|
||||||
}> = (prop) => {
|
}> = (prop) => {
|
||||||
const { value, gen_fields, name, tree_depth, mode } = prop;
|
const { value, gen_fields, name, tree_depth, mode } = prop;
|
||||||
if (gen_fields) {
|
if (gen_fields) {
|
||||||
|
|
@ -54,6 +54,13 @@ export const FormatValue: FC<{
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
return "-";
|
return "-";
|
||||||
}
|
}
|
||||||
|
} else if (mode === "timeago") {
|
||||||
|
if (!value || isEmptyString(value)) return "-";
|
||||||
|
try {
|
||||||
|
return timeAgo(dayjs(value));
|
||||||
|
} catch (ex: any) {
|
||||||
|
return "-";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// await db._batch.update({
|
// await db._batch.update({
|
||||||
// table: "goal",
|
// table: "goal",
|
||||||
|
|
@ -134,3 +141,30 @@ export const FormatValue: FC<{
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
const timeAgo = (date: any) => {
|
||||||
|
try {
|
||||||
|
const now: any = new Date();
|
||||||
|
const secondsPast = Math.floor((now - date) / 1000);
|
||||||
|
|
||||||
|
if (secondsPast < 60) {
|
||||||
|
return `${secondsPast} seconds ago`;
|
||||||
|
} else if (secondsPast < 3600) {
|
||||||
|
const minutesPast = Math.floor(secondsPast / 60);
|
||||||
|
return `${minutesPast} minutes ago`;
|
||||||
|
} else if (secondsPast < 86400) {
|
||||||
|
const hoursPast = Math.floor(secondsPast / 3600);
|
||||||
|
return `${hoursPast} hours ago`;
|
||||||
|
} else if (secondsPast < 604800) {
|
||||||
|
// 7 hari
|
||||||
|
const daysPast = Math.floor(secondsPast / 86400);
|
||||||
|
return `${daysPast} days ago`;
|
||||||
|
} else {
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
||||||
|
const day = date.getDate().toString().padStart(2, "0");
|
||||||
|
return `${day}-${month}-${year}`;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue