Skip to content

Commit

Permalink
🚨 Fix typescript issues after frontend dependency updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pajowu committed Nov 18, 2023
1 parent ea93939 commit da5a218
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 55 deletions.
18 changes: 15 additions & 3 deletions backend/openapi-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,15 @@ components:
- document_id
title: UnknownTask
type: object
UserBase:
properties:
username:
title: Username
type: string
required:
- username
title: UserBase
type: object
ValidationError:
properties:
loc:
Expand Down Expand Up @@ -654,7 +663,8 @@ paths:
'200':
content:
application/json:
schema: {}
schema:
$ref: '#/components/schemas/Document'
description: Successful Response
'422':
content:
Expand Down Expand Up @@ -1282,7 +1292,8 @@ paths:
'200':
content:
application/json:
schema: {}
schema:
$ref: '#/components/schemas/UserBase'
description: Successful Response
'422':
content:
Expand Down Expand Up @@ -1373,7 +1384,8 @@ paths:
'200':
content:
application/json:
schema: {}
schema:
$ref: '#/components/schemas/UserBase'
description: Successful Response
'422':
content:
Expand Down
2 changes: 1 addition & 1 deletion backend/transcribee_backend/routers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def import_document(
token: UserToken = Depends(get_user_token),
session: Session = Depends(get_session),
name: str = Form(),
):
) -> ApiDocument:
document = Document(
name=name,
user_id=token.user_id,
Expand Down
10 changes: 5 additions & 5 deletions backend/transcribee_backend/routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def login(user: CreateUser, session: Session = Depends(get_session)) -> LoginRes
@user_router.post("/logout/")
def logout(
token: UserToken = Depends(get_user_token), session: Session = Depends(get_session)
):
) -> None:
session.delete(token)
session.commit()

Expand All @@ -58,18 +58,18 @@ def logout(
def read_user(
token: UserToken = Depends(get_user_token),
session: Session = Depends(get_session),
):
) -> UserBase:
statement = select(User).where(User.id == token.user_id)
user = session.exec(statement).one()
return {"username": user.username}
return UserBase(username=user.username)


@user_router.post("/change_password/")
def change_password(
body: ChangePasswordRequest,
session: Session = Depends(get_session),
token: UserToken = Depends(get_user_token),
):
) -> UserBase:
try:
authorized_user = authorize_user(
session=session, username=token.user.username, password=body.old_password
Expand All @@ -84,4 +84,4 @@ def change_password(
)
session.execute(delete(UserToken).where(UserToken.user_id == authorized_user.id))
session.commit()
return {"username": user.username}
return UserBase(username=user.username)
7 changes: 6 additions & 1 deletion frontend/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { paths } from './openapi-schema';
import { ApiResponse, Fetcher, Middleware } from 'openapi-typescript-fetch';
import useSwr, { SWRConfiguration } from 'swr';
import useSwr, { SWRConfiguration, SWRResponse } from 'swr';
import { defaultConfig } from 'swr/_internal';

export function getShareToken(): string | null {
Expand Down Expand Up @@ -70,3 +70,8 @@ export function makeRetrySwrHook<P, R>(
...options,
});
}

export type RequestDataType<T extends (...args: never) => SWRResponse> = Exclude<
ReturnType<T>['data'],
undefined
>;
2 changes: 1 addition & 1 deletion frontend/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function LoggedInRedirectRoute<T extends DefaultParams = DefaultParams>({
if (isLoading) {
return <Route component={LoadingPage} />;
}
if (!isLoggedIn && !configLoading) {
if (!isLoggedIn && !configLoading && config !== undefined) {
if (config.logged_out_redirect_url) {
window.location.replace(config.logged_out_redirect_url);
} else {
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/editor/share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { HiOutlineClipboardCopy } from 'react-icons/hi';
import clsx from 'clsx';
import { DialogSeparator } from '../components/dialog';
import { Tooltip } from '../components/tooltip';
import { RequestDataType } from '../api';

type ShareToken = ReturnType<typeof useListShareTokens>['data'][0];
type ShareToken = RequestDataType<typeof useListShareTokens>[0];

function pad(number: number) {
if (number < 10) {
Expand Down Expand Up @@ -235,7 +236,7 @@ export function ShareModal({
</section>
<section className="w-full pt-4 border-t-2 sm:border-t-0 sm:border-l-2 sm:pb-6 sm:pl-6 sm:w-1/2 sm:-mb-6">
<ShareTokenTable
shareTokens={shareTokens}
shareTokens={shareTokens !== undefined ? shareTokens : []}
mutateShareTokens={mutateShareTokens}
documentId={documentId}
/>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/editor/worker_status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { BsRobot } from 'react-icons/bs';
import clsx from 'clsx';
import React from 'react';
import { useMediaQuery } from '../utils/use_media_query';
import { RequestDataType } from '../api';

type Task = ReturnType<typeof useGetDocumentTasks>['data'][0];
type Task = RequestDataType<typeof useGetDocumentTasks>[0];

function formatProgress(task: Task | null): string | undefined {
if (!task) return;
Expand Down Expand Up @@ -45,7 +46,7 @@ export function getWorkerStatusString(isWorking: boolean, isFailed: boolean): st
export function WorkerStatus({ documentId }: { documentId: string }) {
const { data } = useGetDocumentTasks({ document_id: documentId }, { refreshInterval: 1 });

return <WorkerStatusWithData data={data} />;
return <WorkerStatusWithData data={data !== undefined ? data : []} />;
}

function isSuperset<T>(set: Set<T>, subset: Set<T>) {
Expand Down
Loading

0 comments on commit da5a218

Please sign in to comment.