Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reset button to footer #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion client/src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -11,7 +12,10 @@ export default function Footer() {
<div className="container flex flex-col md:flex-row items-center justify-between py-4 text-gray-400">
<LogoSection className="mb-4 h-12 w-24" />

<small className="text-center">©2022, CoEDL</small>
<div className="flex flex-col space-y-2">
<small className="text-center">©2022, CoEDL</small>
<ResetButton />
</div>
<NavSection />
</div>
</div>
Expand Down
27 changes: 27 additions & 0 deletions client/src/components/ResetButton.tsx
Original file line number Diff line number Diff line change
@@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth showing the error message to help diagnose if the reset failed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make this an alert if you'd prefer for all users to see this (which I don't think any will be still). For context, the only way the request is going to fail here should be if the server container is down. The server container also get's restarted immediately if it ever goes down.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's fine then. No need to propagate that error.

}
};

return (
<button className="button" onClick={reset}>
Reset
</button>
);
}
7 changes: 7 additions & 0 deletions client/src/lib/api/reset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import urls, {server} from 'lib/urls';

const url = server + urls.api.reset;

export async function resetApp(): Promise<Response> {
return fetch(url);
}
1 change: 1 addition & 0 deletions client/src/lib/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const urls = {
datasets: '/api/datasets/',
models: '/api/models/',
transcriptions: '/api/transcriptions/',
reset: '/api/reset/',
},
};

Expand Down
3 changes: 2 additions & 1 deletion server/server/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 15 additions & 0 deletions server/server/api/reset.py
Original file line number Diff line number Diff line change
@@ -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)