revert: restore original image handling and page navigation

This commit is contained in:
Erza Bytyci
2026-09-10 16:49:28 +00:00
parent 6f4ad1f8ff
commit d9aec41b30
4 changed files with 8 additions and 100 deletions
-13
View File
@@ -1,13 +0,0 @@
"use client";
export default function Error({ error, reset }) {
return (
<div>
<h2>Etwas ist schiefgelaufen / Something went wrong</h2>
<p>
Ein unerwarteter Fehler ist aufgetreten. Bitte versuchen Sie es erneut.
</p>
<button onClick={() => reset()}>Erneut versuchen / Try again</button>
</div>
);
}
+2 -10
View File
@@ -45,21 +45,13 @@ export default async function Chapters({ params }) {
<Row pb="xl" className="chapter-nav-row" justify="space-between">
<Container className="chapter-nav-left">
{previousLink && (
<LinkButton href={previousLink} hardNavigation>
Zurück
</LinkButton>
)}
{previousLink && <LinkButton href={previousLink}>Zurück</LinkButton>}
</Container>
<Container className="chapter-nav-right">
{showLearningFormLink && (
<LinkButton href="/learning">Go to form</LinkButton>
)}
{nextLink && (
<LinkButton href={nextLink} hardNavigation>
Weiter
</LinkButton>
)}
{nextLink && <LinkButton href={nextLink}>Weiter</LinkButton>}
</Container>
</Row>
</Column>
@@ -134,40 +134,6 @@ function setHtmlContent(quill, html) {
quill.clipboard.dangerouslyPasteHTML(0, content, "api");
}
const MAX_IMAGE_DIMENSION = 1600;
const IMAGE_COMPRESSION_QUALITY = 0.75;
// Downscales/re-encodes images client-side so pasted base64 stays well under proxy body-size limits.
function compressImageFile(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onerror = () => reject(reader.error);
reader.onload = () => {
const img = new Image();
img.onerror = () => reject(new Error("Could not read image"));
img.onload = () => {
const scale = Math.min(
1,
MAX_IMAGE_DIMENSION / Math.max(img.width, img.height)
);
const width = Math.round(img.width * scale);
const height = Math.round(img.height * scale);
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(img, 0, 0, width, height);
const outputType =
file.type === "image/png" ? "image/png" : "image/jpeg";
resolve(canvas.toDataURL(outputType, IMAGE_COMPRESSION_QUALITY));
};
img.src = reader.result;
};
reader.readAsDataURL(file);
});
}
function isNodeEffectivelyEmptyText(node) {
if (!(node instanceof HTMLElement)) {
return false;
@@ -526,34 +492,8 @@ const ClientEditor = (props) => {
[{ script: "sub" }, { script: "super" }],
[{ indent: "-1" }, { indent: "+1" }],
];
const imageHandler = () => {
const input = document.createElement("input");
input.setAttribute("type", "file");
input.setAttribute("accept", "image/*");
input.onchange = async () => {
const file = input.files?.[0];
if (!file) {
return;
}
try {
const dataUrl = await compressImageFile(file);
const range = quill.getSelection(true);
quill.insertEmbed(range.index, "image", dataUrl, "user");
quill.setSelection(range.index + 1, 0, "silent");
} catch (error) {
console.warn("Image compression failed", error);
}
};
input.click();
};
const modules = {
toolbar: {
container: toolbarOptions,
handlers: {
image: imageHandler,
},
},
toolbar: toolbarOptions,
table: false,
"table-better": {
language: "en_US",
+5 -16
View File
@@ -1,7 +1,6 @@
"use client";
import Link from "next/link";
import styles from "@/components/ui/button/button.module.css";
import { withBasePath } from "@/shared/utils/basePath";
export const LinkButton = ({
href,
@@ -10,7 +9,6 @@ export const LinkButton = ({
size = "md",
width = "fit",
className,
hardNavigation = false,
}) => {
const classes = [
styles.baseButton,
@@ -21,21 +19,12 @@ export const LinkButton = ({
]
.filter(Boolean)
.join(" ");
const style = { display: "inline-block", textDecoration: "none" };
// Bypass Next.js soft-navigation (RSC fetch) for pages whose HTML may be too
// large to stream reliably, avoiding client-side crashes on partial responses.
// next/link auto-prefixes basePath; a plain <a> does not, so add it manually.
if (hardNavigation) {
return (
<a href={withBasePath(href)} className={classes} style={style}>
{children}
</a>
);
}
return (
<Link href={href} className={classes} style={style}>
<Link
href={href}
className={classes}
style={{ display: "inline-block", textDecoration: "none" }}
>
{children}
</Link>
);