From 31d0bfa10ca185243a8db7bf8363c69430bd2872 Mon Sep 17 00:00:00 2001 From: Wenderson Pires Date: Fri, 26 Apr 2024 13:04:27 -0300 Subject: [PATCH] fix timeAgo --- src/modules/TimeAgo/timeAgo.ts | 38 +++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/modules/TimeAgo/timeAgo.ts b/src/modules/TimeAgo/timeAgo.ts index 82c5715..5e5ede9 100644 --- a/src/modules/TimeAgo/timeAgo.ts +++ b/src/modules/TimeAgo/timeAgo.ts @@ -3,23 +3,37 @@ import en from "./en"; // TODO: Fazer video tutorial disso // Code builder for "formatTimestamp" -const formatTimestampCode = (timestamp: number) => { - const code = ` - (() => { - TimeAgo.addDefaultLocale({ - ${en} - }); +// const formatTimestampCode = (timestamp: number) => { +// const code = ` +// (() => { +// TimeAgo.addDefaultLocale({ +// ${en} +// }); - return new TimeAgo('en-US').format(new Date(${timestamp})); - })() -`; - return code; -}; +// return new TimeAgo('en-US').format(new Date(${timestamp})); +// })() +// `; +// return code; +// }; + +// const timeAgo = { +// formatTimestamp: (timestamp: number, onComplete: (data: string) => void) => +// ({ +// code: formatTimestampCode(timestamp), +// onComplete, +// } as UseModuleProps), +// }; const timeAgo = { + moduleSetup: ` + TimeAgo.addDefaultLocale({ + ${en} + }) + `, formatTimestamp: (timestamp: number, onComplete: (data: string) => void) => ({ - code: formatTimestampCode(timestamp), + setupCode: timeAgo.moduleSetup, + code: `new TimeAgo('en-US').format(new Date(${timestamp}))`, onComplete, } as UseModuleProps), };