mirror of
https://github.com/CorentinTh/it-tools.git
synced 2026-06-05 13:45:22 -04:00
refactor(tool): better new tool logic
This commit is contained in:
+5
-1
@@ -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,
|
||||
|
||||
@@ -9,6 +9,7 @@ export type Tool = {
|
||||
icon: Component;
|
||||
redirectFrom?: string[];
|
||||
isNew: boolean;
|
||||
createdAt?: Date;
|
||||
};
|
||||
|
||||
export type ToolCategory = {
|
||||
|
||||
Reference in New Issue
Block a user