Added invalidate cache button (through a generic APIButton widget)
parent
095b08e300
commit
2807b551ba
@ -0,0 +1,32 @@
|
||||
import { ToastMessage, useToasts } from '../Toasts.jsx'
|
||||
|
||||
export const APIButton = ({ title, url }) => {
|
||||
const [showToast] = useToasts()
|
||||
|
||||
const fetchAPI = async () => {
|
||||
try {
|
||||
const res = await fetch(url)
|
||||
const status = await res.text()
|
||||
|
||||
if (!res.ok) {
|
||||
showToast(<ToastMessage icon="error">{status}</ToastMessage>)
|
||||
return
|
||||
}
|
||||
|
||||
showToast(<ToastMessage icon="info">Eseguito "{title}"</ToastMessage>)
|
||||
} catch (e) {
|
||||
showToast(<ToastMessage icon="error">Errore "{e}"</ToastMessage>)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div class="title">{title}</div>
|
||||
<div class="content">
|
||||
<div>
|
||||
<button onClick={() => fetchAPI()}>Chiama</button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue