Browse Source

refactor(ui): fix Button link nesting accessibility and add sync failure error toast

master
mortezaei 1 week ago
parent
commit
f08d9edf32
  1. 5
      src/app/questions-list/page.tsx
  2. 76
      src/components/Componentes/button.tsx

5
src/app/questions-list/page.tsx

@ -452,6 +452,11 @@ export default function QuestionsListPage() {
} catch (err) { } catch (err) {
console.error("Failed to sync pending sections:", err); console.error("Failed to sync pending sections:", err);
setIsSyncError(true); setIsSyncError(true);
setToastMessage(
t[
"Sending the match request failed. Please check your connection and try again."
] ?? "Sending the match request failed. Please check your connection and try again."
);
} finally { } finally {
setIsSyncing(false); setIsSyncing(false);
} }

76
src/components/Componentes/button.tsx

@ -153,7 +153,47 @@ export function Button({
); );
}; };
const button = (
const content = isLoading ? (
<LoadingThreeDot />
) : (
<span className="flex w-full items-center justify-center gap-2">
{renderArrow("left")}
<span className="flex min-w-0 flex-col items-center justify-center">
<span className="flex items-center justify-center gap-2 text-center group-16 font-semibold leading-none">
{children}
</span>
{description && !isOutlined ? (
<span
id={countdownId}
className="mt-1 text-center group-10 font-semibold leading-none text-white"
>
{description}
</span>
) : null}
</span>
{countdownLocked ? (
<span className="shrink-0">
<CountdownProgress value={remainingSeconds} progress={progress} />
</span>
) : (
renderArrow("right")
)}
</span>
);
if (href) {
return (
<Link
href={localizePath(href, locale)}
aria-disabled={isDisabled}
className={`${baseClassName} ${isDisabled ? "pointer-events-none" : ""}`}
>
{content}
</Link>
);
}
return (
<button <button
{...props} {...props}
type={type} type={type}
@ -161,41 +201,9 @@ export function Button({
aria-describedby={description && !isOutlined ? countdownId : undefined} aria-describedby={description && !isOutlined ? countdownId : undefined}
className={baseClassName} className={baseClassName}
> >
{isLoading ? (
<LoadingThreeDot />
) : (
<span className="flex w-full items-center justify-center gap-2">
{renderArrow("left")}
<span className="flex min-w-0 flex-col items-center justify-center">
<span className="flex items-center justify-center gap-2 text-center group-16 font-semibold leading-none">
{children}
</span>
{description && !isOutlined ? (
<span
id={countdownId}
className="mt-1 text-center group-10 font-semibold leading-none text-white"
>
{description}
</span>
) : null}
</span>
{countdownLocked ? (
<span className="shrink-0">
<CountdownProgress value={remainingSeconds} progress={progress} />
</span>
) : (
renderArrow("right")
)}
</span>
)}
{content}
</button> </button>
); );
return href ? (
<Link href={localizePath(href, locale)}>{button}</Link>
) : (
button
);
} }
type CountdownProgressProps = { type CountdownProgressProps = {

Loading…
Cancel
Save