Skip to content

Commit fbf109c

Browse files
refactor: restructure types/ folder and fix type definitions
1 parent 293fec2 commit fbf109c

12 files changed

Lines changed: 109 additions & 88 deletions

app/filetypes/[slug]/page.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import fs from 'fs';
33
import path from 'path';
44
import FileTypePageTemplate from '@/components/FileTypePageTemplate';
55
import { transformFileTypeData } from '@/lib/filetype-transformer';
6-
import type { FileTypeRawData, FileTypeTemplateData } from '@/types/filetypes';
6+
import type { FileTypeRawData, FileTypeTemplateData } from '@/types';
77

8-
// Types are now imported from @/types/filetypes
98

109
async function getFileTypeData(slug: string): Promise<FileTypeTemplateData | null> {
1110
try {

components/HeroConverter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export default function HeroConverter({
241241
<AlertTriangle className="h-4 w-4" />
242242
<AlertDescription>
243243
<strong>Note:</strong> Video conversion runs in your browser using WebAssembly.
244-
Large files (>50MB) may take several minutes. For MKV→MP4/MOV, we use fast remuxing when possible.
244+
Large files (&gt;50MB) may take several minutes. For MKV→MP4/MOV, we use fast remuxing when possible.
245245
</AlertDescription>
246246
</Alert>
247247
)}

components/ToolPageTemplate.tsx

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,56 +8,25 @@ import { FAQSection } from "@/components/sections/FAQSection";
88
import { ToolsLinkHub } from "@/components/sections/ToolsLinkHub";
99
import { BlogSection } from "@/components/sections/BlogSection";
1010
import { ChangelogSection } from "@/components/sections/ChangelogSection";
11-
12-
type ToolInfo = {
13-
title: string;
14-
subtitle: string;
15-
from: string;
16-
to: string;
17-
accept?: string;
18-
};
11+
import type {
12+
ToolInfo,
13+
VideoSectionData,
14+
FAQ,
15+
AboutFormatsSection as AboutFormatsSectionData,
16+
ChangelogEntry,
17+
RelatedTool,
18+
BlogPost
19+
} from "@/types";
1920

2021
type ToolPageProps = {
2122
tool: ToolInfo;
22-
videoSection?: {
23-
embedId?: string;
24-
};
23+
videoSection?: VideoSectionData;
2524
useTwoColumnLayout?: boolean;
26-
faqs?: Array<{
27-
question: string;
28-
answer: string;
29-
}>;
30-
aboutSection?: {
31-
title?: string;
32-
fromFormat: {
33-
name: string;
34-
fullName: string;
35-
description: string;
36-
details?: string[];
37-
};
38-
toFormat: {
39-
name: string;
40-
fullName: string;
41-
description: string;
42-
details?: string[];
43-
};
44-
};
45-
changelog?: Array<{
46-
date: string;
47-
changes: string[];
48-
}>;
49-
relatedTools?: Array<{
50-
title: string;
51-
href: string;
52-
}>;
53-
blogPosts?: Array<{
54-
title: string;
55-
subtitle: string;
56-
description: string;
57-
href: string;
58-
category?: string;
59-
image?: string;
60-
}>;
25+
faqs?: FAQ[];
26+
aboutSection?: AboutFormatsSectionData;
27+
changelog?: ChangelogEntry[];
28+
relatedTools?: RelatedTool[];
29+
blogPosts?: BlogPost[];
6130
};
6231

6332
export default function ToolPageTemplate({

components/ToolsByCategory.tsx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
"use client";
22

3-
import { Tool } from '@/lib/tool-utils';
4-
import { categoryDefinitions, MainCategory } from '@/config/tool-categories';
3+
import type { Tool } from '@/types';
4+
import { tools } from '@/lib/tool-utils';
55
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
66
import Link from 'next/link';
7-
import { ArrowRightLeft, Minimize2, Combine, Edit, BarChart, Sparkles } from 'lucide-react';
7+
import { ArrowRightLeft, Minimize2, Combine, Download } from 'lucide-react';
88

99
const categoryIcons = {
1010
convert: ArrowRightLeft,
1111
compress: Minimize2,
1212
combine: Combine,
13-
edit: Edit,
14-
analyze: BarChart,
15-
generate: Sparkles,
13+
download: Download,
14+
};
15+
16+
type MainCategory = 'convert' | 'compress' | 'combine' | 'download';
17+
18+
const categoryDefinitions = {
19+
convert: { name: 'Convert', color: 'blue' },
20+
compress: { name: 'Compress', color: 'green' },
21+
combine: { name: 'Combine', color: 'purple' },
22+
download: { name: 'Download', color: 'red' },
1623
};
1724

1825
interface ToolsByCategoryProps {
@@ -23,16 +30,17 @@ interface ToolsByCategoryProps {
2330
export function ToolsByCategory({ tools, selectedCategory }: ToolsByCategoryProps) {
2431
// Group tools by category
2532
const toolsByCategory = tools.reduce((acc, tool) => {
26-
if (!acc[tool.category]) {
27-
acc[tool.category] = [];
33+
const category = tool.operation as MainCategory;
34+
if (!acc[category]) {
35+
acc[category] = [];
2836
}
29-
acc[tool.category].push(tool);
37+
acc[category].push(tool);
3038
return acc;
3139
}, {} as Record<MainCategory, Tool[]>);
3240

3341
// Sort tools by priority within each category
3442
Object.keys(toolsByCategory).forEach(category => {
35-
toolsByCategory[category as MainCategory].sort((a, b) =>
43+
toolsByCategory[category as MainCategory].sort((a: Tool, b: Tool) =>
3644
(b.priority || 0) - (a.priority || 0)
3745
);
3846
});
@@ -58,15 +66,14 @@ export function ToolsByCategory({ tools, selectedCategory }: ToolsByCategoryProp
5866
</div>
5967
<div>
6068
<h2 className="text-2xl font-bold">{categoryInfo.name} Tools</h2>
61-
<p className="text-muted-foreground">{categoryInfo.description}</p>
6269
</div>
6370
<span className="ml-auto px-3 py-1 rounded-full bg-muted text-sm font-medium">
6471
{categoryTools.length} tools
6572
</span>
6673
</div>
6774

6875
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
69-
{categoryTools.map(tool => (
76+
{categoryTools.map((tool: Tool) => (
7077
<Link key={tool.id} href={tool.route}>
7178
<Card className="h-full hover:shadow-lg transition-all hover:-translate-y-0.5 cursor-pointer">
7279
<CardHeader className="pb-3">
@@ -83,16 +90,11 @@ export function ToolsByCategory({ tools, selectedCategory }: ToolsByCategoryProp
8390
<p className="text-sm text-muted-foreground line-clamp-2">
8491
{tool.description}
8592
</p>
86-
{tool.subcategory && (
93+
{tool.from && tool.to && (
8794
<div className="mt-3 flex items-center gap-2">
88-
<span className="text-xs px-2 py-1 rounded-full bg-muted">
89-
{tool.subcategory.replace(/-/g, ' ')}
95+
<span className="text-xs text-muted-foreground">
96+
{tool.from.toUpperCase()}{tool.to.toUpperCase()}
9097
</span>
91-
{tool.from && tool.to && (
92-
<span className="text-xs text-muted-foreground">
93-
{tool.from.toUpperCase()}{tool.to.toUpperCase()}
94-
</span>
95-
)}
9698
</div>
9799
)}
98100
</CardContent>

components/ToolsByTaxonomy.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import type { Tool, OperationType, MediaType } from '@/types/tools';
3+
import type { Tool, OperationType, MediaType } from '@/types';
44
import {
55
operationDefinitions,
66
mediaTypeDefinitions,
@@ -25,6 +25,13 @@ const mediaIcons = {
2525
text: FileText,
2626
};
2727

28+
interface ToolWithMedia extends Tool {
29+
mediaTypes?: {
30+
source?: MediaType;
31+
target?: MediaType;
32+
};
33+
}
34+
2835
interface ToolsByTaxonomyProps {
2936
tools: Tool[];
3037
groupBy?: 'operation' | 'media';
@@ -39,7 +46,7 @@ export function ToolsByTaxonomy({
3946
selectedMediaType
4047
}: ToolsByTaxonomyProps) {
4148
// Add media types to tools
42-
const toolsWithMedia = tools.map(tool => ({
49+
const toolsWithMedia: ToolWithMedia[] = tools.map(tool => ({
4350
...tool,
4451
mediaTypes: {
4552
source: tool.from ? formatToMediaType[tool.from.toLowerCase()] : undefined,
@@ -67,7 +74,7 @@ export function ToolsByTaxonomy({
6774
}
6875
acc[tool.operation].push(tool);
6976
return acc;
70-
}, {} as Record<OperationType, Tool[]>);
77+
}, {} as Record<OperationType, ToolWithMedia[]>);
7178

7279
// Sort tools by priority within each operation
7380
Object.keys(toolsByOperation).forEach(operation => {

components/sections/BlogSection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
type BlogPost = {
22
title: string;
3-
subtitle: string;
4-
description: string;
3+
subtitle?: string;
4+
description?: string;
55
href: string;
66
category?: string;
77
image?: string;

lib/filetype-categories.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ export const extensionToCategory: Record<string, FileCategory> = {
195195

196196
// Developer Files
197197
'js': 'developer',
198-
'ts': 'developer',
199198
'jsx': 'developer',
200199
'tsx': 'developer',
201200
'py': 'developer',

lib/filetype-transformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FileTypeRawData, FileTypeTemplateData } from '@/types/filetypes';
1+
import type { FileTypeRawData, FileTypeTemplateData } from '@/types';
22
import toolsData from '@/data/tools.json';
33

44
/**

lib/tool-content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Helper to get tool content from the tools data
22
import toolsData from '@/data/tools.json';
3-
import type { Tool, ToolContent } from '@/types/tools';
3+
import type { Tool, ToolContent } from '@/types';
44

55
const tools = toolsData as Tool[];
66

lib/tool-utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Tool, OperationType, MediaType } from '@/types/tools';
2-
import type { OperationDefinitions, MediaTypeDefinitions } from '@/types/taxonomy';
1+
import type { Tool, OperationType, MediaType } from '@/types';
2+
import type { OperationDefinitions, MediaTypeDefinitions } from '@/types';
33
import toolsData from '@/data/tools.json';
44

55
// Cast the imported JSON to our Tool type
@@ -157,7 +157,7 @@ export const formatToMediaType: Record<string, MediaType> = {
157157
'wav': 'audio',
158158
'flac': 'audio',
159159
'aac': 'audio',
160-
'ogg': 'audio',
160+
'oga': 'audio',
161161
'wma': 'audio',
162162
'm4a': 'audio',
163163
'opus': 'audio',
@@ -236,7 +236,6 @@ export const formatToMediaType: Record<string, MediaType> = {
236236
'html': 'text',
237237
'css': 'text',
238238
'js': 'text',
239-
'ts': 'text',
240239
'jsx': 'text',
241240
'tsx': 'text',
242241
'py': 'text',

0 commit comments

Comments
 (0)