Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
"description": "Kodiert oder dekodiert Text als Base64"
}
},
"conversion": {
"title": "Umrechnung",
"CelciusToFahrenheit": {
"title": "Celcius zu Fahrenheit",
"description": "Temperaturumrechner"
}
},
"color": {
"title": "Farbe",
"hexToHSL": {
Expand Down Expand Up @@ -121,7 +128,7 @@
"title": "Hex zu HSL",
"description": "Konvertiert eine Hex-Farbe in das HSL-Format.",
"options": {
"valuesOnly": "In hsl(...) einfügen"
"valuesOnly": "In hsl(...) einfügen"
}
}
},
Expand All @@ -134,6 +141,17 @@
"dropFiles": "Dateien hierhin ziehen und ablegen oder klicken, um auszuwählen"
}
}
},
"conversion": {
"CelciusToFahrenheit": {
"title": "Fahrenheit ⇄ Celsius Rechner",
"fahrenheit": "Fahrenheit",
"celcius": "Celcius",
"description": {
"title": "Was macht dieser Converter?",
"text": "Dieser Converter rechnet Temperaturen zwischen Fahrenheit und Celsius um. Gib einen Wert ein und erhalte sofort das Ergebnis in der anderen Einheit."
}
}
}
},
"translationTable": {
Expand All @@ -144,4 +162,4 @@
"swapSides": "Seiten tauschen",
"clearInput": "Eingabe löschen"
}
}
}
20 changes: 19 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@
"description": "Encode or decode text as Unicode Binary"
}
},
"conversion": {
"title": "Conversion",
"CelciusToFahrenheit": {
"title": "Celcius To Fahrenheit",
"description": "Temperature Converter"
}
},
"color": {
"title": "Color",
"hexToHSL": {
Expand Down Expand Up @@ -131,7 +138,7 @@
"title": "Hex to HSL",
"description": "Converts a hex color to HSL format.",
"options": {
"valuesOnly": "Include in hsl(...)"
"valuesOnly": "Include in hsl(...)"
}
}
},
Expand All @@ -144,6 +151,17 @@
"dropFiles": "Drag & drop files here, or click to select"
}
}
},
"conversion": {
"CelciusToFahrenheit": {
"title": "Fahrenheit ⇄ Celsius converter",
"fahrenheit": "Fahrenheit",
"celcius": "Celcius",
"description": {
"title": "What does this converter do?",
"text": "This converter converts temperatures between Fahrenheit and Celsius. Enter a value and get the result in the other unit instantly."
}
}
}
},
"translationTable": {
Expand Down
74 changes: 74 additions & 0 deletions src/app/[locale]/(tools)/conversion/celcius-to-fahrenheit/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"use client"
import { Section } from "@/components/ui/Section";
import { useState } from "react";
import { convertTemp } from "./tempraturConverter";
import { useTranslations } from "next-intl";


export default function TemperatureConverter() {
const [fahrenheit, setFahrenheit] = useState("");
const [celsius, setCelsius] = useState("");

const t = useTranslations("tools.conversion.CelciusToFahrenheit")

// Handlers for input changes
function handleFahrenheitChange(e: React.ChangeEvent<HTMLInputElement>) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used two separate functions because I couldn't figure out how to put it all in one and still know which way to convert the value.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reference the handleCelsiusChange and handleFahrenheitChange functions. I feel like there could be a better way

const value = e.target.value;
setFahrenheit(value);
const num = parseFloat(value);

if (isNaN(num)) {
setCelsius("");
return;
}

setCelsius(convertTemp("FC", num).toFixed(2) + "°C");
}

function handleCelsiusChange(e: React.ChangeEvent<HTMLInputElement>) {
const value = e.target.value;
setCelsius(value);
const num = parseFloat(value);
if (isNaN(num)) {
setFahrenheit("");
return;
}
setFahrenheit(convertTemp("CF", num).toFixed(2) + "°F");
}

return (
<div className="flex flex-col gap-6 pt-4 max-w-md mx-auto">
<h2 className="text-lg font-semibold mb-2 text-center">{t("title")}</h2>
<div className="flex flex-row gap-4 justify-center items-center">
<div className="flex flex-col items-center">
<label className="text-sm mb-1" htmlFor="fahrenheit">{t("fahrenheit")}</label>
<input
id="fahrenheit"
value={fahrenheit}
onChange={handleFahrenheitChange}
className="w-28 px-2 py-1 rounded border border-gray-300 text-center"
placeholder="°F"
/>
</div>
<span className="text-xl font-bold">⇄</span>
<div className="flex flex-col items-center">
<label className="text-sm mb-1" htmlFor="celsius">{t("celcius")}</label>
<input
id="celsius"
value={celsius}
onChange={handleCelsiusChange}
className="w-28 px-2 py-1 rounded border border-gray-300 text-center"
placeholder="°C"
/>
</div>
</div>
<Section variant="ghost">
<h2 className="header-section-2">{t("description.title")}</h2>
<p>
{t("description.text")}
</p>
</Section>
</div>
);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function convertTemp(mode: "CF" | "FC", input: number): number {
let newTemp: number;
if (mode == 'CF') {
newTemp = CF(input);
} else {
newTemp = FC(input);
}
return newTemp;
}

export function CF(input: number): number {
return input * 1.8 + 32
}

export function FC(input: number): number {
return (input - 32) / 1.8
}

2 changes: 1 addition & 1 deletion src/app/[locale]/(tools)/pdf/SampleGenerator/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function PDFSampleGenerator() {

const pdfBytes = await pdfDoc.save()

const blob = new Blob([pdfBytes], { type: 'application/pdf' });
const blob = new Blob([pdfBytes as BlobPart], { type: 'application/pdf' });

await saveBlobToFileWithDialog(blob);
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/[locale]/(tools)/pdf/split/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function PDFSplit() {
(async () => {
const newPdfFile = await PDFDocument.load(await file.arrayBuffer());


setPdfFile(newPdfFile);
setFileNameWithoutExtension(file.name.split(".").slice(0, -1).join("."));

Expand Down Expand Up @@ -81,7 +82,7 @@ export default function PDFSplit() {
for (let i = 0; i < splittedPDFs.length; i++) {
const pdf = splittedPDFs[i];
const pdfBytes = await pdf.save();
const pdfReader = new BlobReader(new Blob([pdfBytes]));
const pdfReader = new BlobReader(new Blob([pdfBytes as BlobPart]));
await zipWriter.add(`${fileNameWithoutExtension}-${i + 1}.pdf`, pdfReader);
}

Expand Down
12 changes: 12 additions & 0 deletions src/lib/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ export const menuData: Array<NavigationGroupTranslationKey & DisplayInMenuField
}
],
},
{
translationKey: "tools.conversion",
displayInMenu: true,
items: [
{
translationKey: "CelciusToFahrenheit",
href: "/conversion/celcius-to-fahrenheit",
displayInMenu: true,
icon: UpdateIcon,
}
]
},
{
translationKey: "tools.color",
displayInMenu: true,
Expand Down