refactor: apply Astro, Preact, and general best practices to src
- Refactored all components in src/components to: - Use arrow function components and prop destructuring - Add JSDoc for all exported components - Improve accessibility (aria-labels, roles, etc.) - Use correct key usage in lists - Add comments for non-obvious logic - Use modern event handler patterns and memoization where appropriate - Refactored src/pages/index.astro: - Removed <html>, <head>, and <body> (should be in layout) - Used semantic <main> for main content - Kept only necessary imports and markup - Refactored src/styles/index.css: - Removed duplicate rules - Ensured only global resets/utilities are present - Added comments for clarity - Ensured no component-specific styles are present - Used consistent formatting Brings the codebase in line with modern Astro and Preact best practices, improves maintainability, accessibility, and code clarity.
This commit is contained in:
@@ -1,26 +1,36 @@
|
||||
import { h } from 'preact';
|
||||
import styles from './GameCompletionModal.module.css';
|
||||
|
||||
export default function GameCompletionModal({ open, game, onConfirm, onClose }) {
|
||||
/**
|
||||
* Modal shown when a game is completed.
|
||||
* @param {object} props
|
||||
* @param {boolean} props.open
|
||||
* @param {object} props.game
|
||||
* @param {Function} props.onConfirm
|
||||
* @param {Function} props.onClose
|
||||
* @returns {import('preact').VNode|null}
|
||||
*/
|
||||
const GameCompletionModal = ({ open, game, onConfirm, onClose }) => {
|
||||
if (!open || !game) return null;
|
||||
const playerNames = [game.player1, game.player2, game.player3].filter(Boolean);
|
||||
const scores = [game.score1, game.score2, game.score3].filter((_, i) => playerNames[i]);
|
||||
const maxScore = Math.max(...scores);
|
||||
// Find all winners (could be a tie)
|
||||
const winners = playerNames.filter((name, idx) => scores[idx] === maxScore);
|
||||
const winnerText = winners.length > 1
|
||||
? `Unentschieden zwischen ${winners.join(' und ')}`
|
||||
: `${winners[0]} hat gewonnen!`;
|
||||
return (
|
||||
<div id="game-completion-modal" className="modal show">
|
||||
<div id="game-completion-modal" className="modal show" role="dialog" aria-modal="true" aria-labelledby="completion-modal-title">
|
||||
<div className={styles['modal-content']}>
|
||||
<div className={styles['modal-header']}>
|
||||
<span className={styles['modal-title']}>Spiel beendet</span>
|
||||
<button className={styles['close-button']} onClick={onClose}>×</button>
|
||||
<span className={styles['modal-title']} id="completion-modal-title">Spiel beendet</span>
|
||||
<button className={styles['close-button']} onClick={onClose} aria-label="Schließen">×</button>
|
||||
</div>
|
||||
<div className={styles['modal-body']}>
|
||||
<div className={styles['final-scores']}>
|
||||
{playerNames.map((name, idx) => (
|
||||
<div className={styles['final-score']} key={name}>
|
||||
<div className={styles['final-score']} key={name + idx}>
|
||||
<span className={styles['player-name']}>{name}</span>
|
||||
<span className={styles['score']}>{scores[idx]}</span>
|
||||
</div>
|
||||
@@ -29,10 +39,12 @@ export default function GameCompletionModal({ open, game, onConfirm, onClose })
|
||||
<div className={styles['winner-announcement']}><h3>{winnerText}</h3></div>
|
||||
</div>
|
||||
<div className={styles['modal-footer']}>
|
||||
<button className={styles['btn'] + ' ' + styles['btn--warning']} onClick={onConfirm}>Bestätigen</button>
|
||||
<button className={styles['btn']} onClick={onClose}>Abbrechen</button>
|
||||
<button className={styles['btn'] + ' ' + styles['btn--warning']} onClick={onConfirm} aria-label="Bestätigen">Bestätigen</button>
|
||||
<button className={styles['btn']} onClick={onClose} aria-label="Abbrechen">Abbrechen</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default GameCompletionModal;
|
||||
Reference in New Issue
Block a user