File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export default function WordForm({ onAddWordAction }: WordFormProps) {
2020 < Input
2121 className = "px-4"
2222 name = "word"
23- placeholder = "Deutsches Wort eingeben"
23+ placeholder = "Deutsches Wort eingeben, z.B. Brief "
2424 required
2525 />
2626 < Button className = "px-4 py-2" type = "submit" >
Original file line number Diff line number Diff line change @@ -37,11 +37,21 @@ export default function Wortilizer() {
3737 return
3838 }
3939
40- if ( wortschatz . find ( ( wortschatzEntry ) => wortschatzEntry . word === word ) ) {
41- console . error ( 'Word exists in vocabulary' )
40+ // If a word is already in the vocab, move it to first position
41+ const foundWortschatzEntry = wortschatz . find (
42+ ( wortschatzEntry ) => wortschatzEntry . word === word
43+ )
44+ if ( foundWortschatzEntry ) {
45+ saveWortschatz ( ( prevWortschatz ) => {
46+ const restPrevWortschatz = prevWortschatz . filter (
47+ ( wortschatzEntry ) => wortschatzEntry . word !== word
48+ )
49+ return [ foundWortschatzEntry , ...restPrevWortschatz ]
50+ } )
4251 return
4352 }
4453
54+ // All good, just add the word
4555 const wortschatzEntry : WortschatzEntry = {
4656 word,
4757 article,
You can’t perform that action at this time.
0 commit comments