diff --git a/client/src/components/Footer.tsx b/client/src/components/Footer.tsx index 879fdfa..0eea25c 100644 --- a/client/src/components/Footer.tsx +++ b/client/src/components/Footer.tsx @@ -2,6 +2,7 @@ import navLinks from 'lib/navLinks'; import Link from 'next/link'; import React from 'react'; import Logo from './Logo'; +import ResetButton from './ResetButton'; const LINK_STYLE = 'font-display hover:underline'; @@ -11,7 +12,10 @@ export default function Footer() {
- ©2022, CoEDL +
+ ©2022, CoEDL + +
diff --git a/client/src/components/ResetButton.tsx b/client/src/components/ResetButton.tsx new file mode 100644 index 0000000..09f8685 --- /dev/null +++ b/client/src/components/ResetButton.tsx @@ -0,0 +1,27 @@ +import {useAtom} from 'jotai'; +import {resetApp} from 'lib/api/reset'; +import React from 'react'; +import {datasetsAtom, modelsAtom, transcriptionsAtom} from 'store'; + +export default function ResetButton() { + const [, setDatasets] = useAtom(datasetsAtom); + const [, setModels] = useAtom(modelsAtom); + const [, setTranscriptions] = useAtom(transcriptionsAtom); + + const reset = async () => { + const response = await resetApp(); + if (response.ok) { + setDatasets([]); + setModels([]); + setTranscriptions([]); + } else { + console.error('Error resetting app'); + } + }; + + return ( + + ); +} diff --git a/client/src/lib/api/reset.ts b/client/src/lib/api/reset.ts new file mode 100644 index 0000000..e61d48a --- /dev/null +++ b/client/src/lib/api/reset.ts @@ -0,0 +1,7 @@ +import urls, {server} from 'lib/urls'; + +const url = server + urls.api.reset; + +export async function resetApp(): Promise { + return fetch(url); +} diff --git a/client/src/lib/urls.ts b/client/src/lib/urls.ts index d381e68..71118cb 100644 --- a/client/src/lib/urls.ts +++ b/client/src/lib/urls.ts @@ -22,6 +22,7 @@ export const urls = { datasets: '/api/datasets/', models: '/api/models/', transcriptions: '/api/transcriptions/', + reset: '/api/reset/', }, }; diff --git a/server/server/api/__init__.py b/server/server/api/__init__.py index 670a9c1..a347af5 100644 --- a/server/server/api/__init__.py +++ b/server/server/api/__init__.py @@ -2,9 +2,10 @@ from server.api.datasets import dataset_bp from server.api.models import model_bp +from server.api.reset import reset_bp from server.api.transcribe import transcription_bp api_bp = Blueprint("api_bp", __name__, url_prefix="/api") -for bp in dataset_bp, model_bp, transcription_bp: +for bp in dataset_bp, model_bp, transcription_bp, reset_bp: api_bp.register_blueprint(bp) diff --git a/server/server/api/reset.py b/server/server/api/reset.py new file mode 100644 index 0000000..281d87a --- /dev/null +++ b/server/server/api/reset.py @@ -0,0 +1,15 @@ +from http import HTTPStatus + +from flask import Blueprint, Response +from flask import current_app as app + +from server.interface import Interface + +reset_bp = Blueprint("reset_bp", __name__, url_prefix="/reset") + + +@reset_bp.route("/", methods=["GET"]) +def reset(): + interface = Interface.from_app(app) + interface.reset() + return Response(status=HTTPStatus.NO_CONTENT)