Skip to content

Commit

Permalink
refactor(tool): better new tool logic
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinTh committed Apr 5, 2023
1 parent 2028298 commit fb8a3a0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions scripts/create-tool.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const tool = defineTool({
keywords: ['${toolName.split('-').join("', '")}'],
component: () => import('./${toolName}.vue'),
icon: ArrowsShuffle,
createdAt: new Date('${new Date().toISOString().split('T')[0]}'),
});
`,
);
Expand Down
6 changes: 5 additions & 1 deletion src/tools/tool.ts
Original file line number Diff line number Diff line change
@@ -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>>;
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/tools/tools.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type Tool = {
icon: Component;
redirectFrom?: string[];
isNew: boolean;
createdAt?: Date;
};

export type ToolCategory = {
Expand Down

0 comments on commit fb8a3a0

Please sign in to comment.