aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Corentin Thomasset <corentin.thomasset74@gmail.com> 2023-04-05 23:30:44 +0200
committerGravatar Corentin Thomasset <corentin.thomasset74@gmail.com> 2023-04-05 23:30:44 +0200
commitfb8a3a0fee058bfd9f4ae22a00e6406719e1d06f (patch)
tree765a512646211ab8487e85bded1758f976c2e33e /src
parent20282987e30a04cd1f79fa0a642ab928455eec02 (diff)
downloadit-tools-fb8a3a0fee058bfd9f4ae22a00e6406719e1d06f.tar.gz
it-tools-fb8a3a0fee058bfd9f4ae22a00e6406719e1d06f.tar.zst
it-tools-fb8a3a0fee058bfd9f4ae22a00e6406719e1d06f.zip
refactor(tool): better new tool logic
Diffstat (limited to 'src')
-rw-r--r--src/tools/tool.ts6
-rw-r--r--src/tools/tools.types.ts1
2 files changed, 6 insertions, 1 deletions
diff --git a/src/tools/tool.ts b/src/tools/tool.ts
index 8289aa3..a5d157e 100644
--- a/src/tools/tool.ts
+++ b/src/tools/tool.ts
@@ -1,4 +1,5 @@
import { config } from '@/config';
+import { isAfter, subWeeks } from 'date-fns';
import type { Tool } from './tools.types';
type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
@@ -7,7 +8,10 @@ export function defineTool(
tool: WithOptional<Tool, 'isNew'>,
{ newTools }: { newTools: string[] } = { newTools: config.tools.newTools },
) {
- const isNew = newTools.includes(tool.name);
+ const isInNewToolConfig = newTools.includes(tool.name);
+ const isRecentTool = tool.createdAt ? isAfter(tool.createdAt, subWeeks(new Date(), 2)) : false;
+
+ const isNew = isInNewToolConfig || isRecentTool;
return {
isNew,
diff --git a/src/tools/tools.types.ts b/src/tools/tools.types.ts
index 5630a12..48f6062 100644
--- a/src/tools/tools.types.ts
+++ b/src/tools/tools.types.ts
@@ -9,6 +9,7 @@ export type Tool = {
icon: Component;
redirectFrom?: string[];
isNew: boolean;
+ createdAt?: Date;
};
export type ToolCategory = {