Skip to content

Commit

Permalink
prevent several requests of activation, deactivation or deletion for …
Browse files Browse the repository at this point in the history
…the same vocab by user incl. preventing displaying the toast message twice
  • Loading branch information
nora-kauczor committed Nov 15, 2024
1 parent be777f5 commit 05e0a47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 12 additions & 3 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,13 @@ function App() {
}

function activateVocab(id: string): void {
if (toast.isActive(`activate-vocab-${id}`)) {
return;
}
axios.put(`api/vocab/activate/${id}`)
.then(() => {
console.log(`Successfully activated vocab with ID ${id}.`)
toast.success("Vocab successfully activated.")
toast.success("Vocab successfully activated.", { toastId: `activate-vocab-${id}` })
getAllVocabsOfLanguage()
})
.catch(error => {
Expand All @@ -138,10 +141,13 @@ function App() {
}

function deactivateVocab(id: string): void {
if (toast.isActive(`deactivate-vocab-${id}`)) {
return;
}
axios.put(`api/vocab/deactivate/${id}`)
.then(() => {
console.log(`Successfully deactivated vocab with ID ${id}.`)
toast.success("Vocab successfully deactivated.")
toast.success("Vocab successfully deactivated.", { toastId: `deactivate-vocab-${id}` })
getAllVocabsOfLanguage()
})
.catch(error => {
Expand All @@ -167,10 +173,13 @@ function App() {
}

function deleteVocab(id: string): void {
if (toast.isActive(`delete-vocab-${id}`)) {
return;
}
axios.delete(`api/vocab/${id}`)
.then(() => {
console.log(`Successfully deleted vocab with ID ${id}.`)
toast.success("Vocab successfully deleted")
toast.success("Vocab successfully deleted", { toastId: `delete-vocab-${id}` })
getAllVocabsOfLanguage()
})
.catch(error => {
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/components/VocabList/VocabList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default function VocabList(props: Readonly<Props>) {
const navigate = useNavigate()

function handleClickActivate(id: string | null): void {
// TODO falls gerade toast gezeigt wird, return
if (!id || !props.activateVocab) {
return
}
Expand All @@ -27,7 +26,6 @@ export default function VocabList(props: Readonly<Props>) {
}

function handleClickDeactivate(id: string | null): void {
// TODO falls gerade toast gezeigt wird, return
if (!id || !props.deactivateVocab) {
return
}
Expand All @@ -45,7 +43,6 @@ export default function VocabList(props: Readonly<Props>) {
}

function handleClickDelete(id: string | null) {
// TODO falls gerade toast gezeigt wird, return
if (!id || !props.deleteVocab) {
return
}
Expand Down

0 comments on commit 05e0a47

Please sign in to comment.