-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a text view similar to the previous version
- Loading branch information
Showing
9 changed files
with
347 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Participant } from '../types'; | ||
import { useState, useEffect } from 'react'; | ||
import { parseParticipantsText, ParseError, formatParticipantText } from '../utils/parseParticipants'; | ||
import { ArrowsClockwise } from '@phosphor-icons/react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
interface ParticipantsTextViewProps { | ||
participants: Record<string, Participant>; | ||
onChangeParticipants: (newParticipants: Record<string, Participant>) => void; | ||
onGeneratePairs: () => void; | ||
} | ||
|
||
export function ParticipantsTextView({ participants, onChangeParticipants, onGeneratePairs }: ParticipantsTextViewProps) { | ||
const { t } = useTranslation(); | ||
|
||
const [text, setText] = useState(() => formatParticipantText(participants)); | ||
const [error, setError] = useState<ParseError | null>(null); | ||
|
||
const handleChange = (newText: string) => { | ||
setText(newText); | ||
|
||
const result = parseParticipantsText(newText); | ||
if (result.ok) { | ||
setError(null); | ||
onChangeParticipants(result.participants); | ||
} else { | ||
setError(result); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="relative space-y-2"> | ||
<textarea | ||
className={`block w-full h-48 p-2 font-mono text-sm border rounded text-nowrap ${ | ||
error ? 'border-red-500' : '' | ||
}`} | ||
value={text} | ||
onChange={e => handleChange(e.target.value)} | ||
/> | ||
|
||
{error && ( | ||
<div className="bg-red-100 text-red-700 text-sm p-2 rounded"> | ||
{t('errors.line', { number: error.line })}: {t(error.key as any, error.values)} | ||
</div> | ||
)} | ||
|
||
<button | ||
type="button" | ||
onClick={onGeneratePairs} | ||
className="w-full bg-green-500 text-white p-2 rounded hover:bg-blue-600 flex items-center justify-center gap-2" | ||
> | ||
<ArrowsClockwise size={20} weight="bold" /> | ||
{t('participants.generatePairs')} | ||
</button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.