Skip to content

Commit

Permalink
switch to typescript-fetch for api generation
Browse files Browse the repository at this point in the history
  • Loading branch information
acrantel committed Aug 19, 2023
1 parent 1e17ddf commit 62c7d07
Show file tree
Hide file tree
Showing 141 changed files with 9,704 additions and 6,764 deletions.
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ repos:
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
exclude: ^frontend2/src/utils/types
- id: mixed-line-ending
args: ["--fix=lf"]
exclude: ^frontend2/src/utils/types
- id: trailing-whitespace
exclude: ^frontend2/src/utils/types

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
types_or: [css, html, javascript, json, jsx, markdown]
exclude: ^frontend/public/assets
exclude: ^frontend/public/assets | ^frontend2/src/utils/types

- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
Expand Down
1 change: 0 additions & 1 deletion frontend2/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/node_modules
/.pnp
.pnp.js
/types

# production
/build
Expand Down
2 changes: 1 addition & 1 deletion frontend2/generate_types.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ python backend/manage.py spectacular --file schema.yml
:: npm install @openapitools/openapi-generator-cli -g
:: if you have a java error, just install java 8 and reload terminal
echo "Generate typescript types from schema"
npx @openapitools/openapi-generator-cli generate -i schema.yml -o frontend2/src/utils/types -g typescript-jquery --additional-properties=modelPropertyNaming=camelCase --additional-properties=disallowAdditionalPropertiesIfNotPresent=false
npx @openapitools/openapi-generator-cli generate -i schema.yml -o frontend2/src/utils/types -g typescript-fetch --additional-properties=modelPropertyNaming=original --additional-properties=disallowAdditionalPropertiesIfNotPresent=false --additional-properties=stringEnums=true
8 changes: 4 additions & 4 deletions frontend2/src/components/BattlecodeTableBottomElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ const BattlecodeTableBottomElement: React.FC<TableBottomProps> = ({
return [1, "..."].concat(
Array.from(
{ length: MAX_PAGES - 2 },
(_, idx) => pageCount - MAX_PAGES + idx + 3
)
(_, idx) => pageCount - MAX_PAGES + idx + 3,
),
);
} else {
return [1, "..."]
.concat(
Array.from(
{ length: MAX_PAGES - 4 },
(_, idx) => idx + currentPage - 5
)
(_, idx) => idx + currentPage - 5,
),
)
.concat(["...", pageCount]);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend2/src/components/CurrentUserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const CurrentUserProvider: React.FC<{ children: React.ReactNode }> = ({
useEffect(() => {
const checkLoggedIn = async (): Promise<void> => {
// check if cookies exist before attempting to load user
if (!doApiTokensExist()) {
if (!(await Api.verifyCurrentToken())) {
logout();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion frontend2/src/components/elements/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface InputProps extends React.ComponentPropsWithoutRef<"input"> {

const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
{ label, required, ...rest },
ref
ref,
) {
required = required ?? false;
return (
Expand Down
8 changes: 4 additions & 4 deletions frontend2/src/components/sidebar/__test__/Sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ test("UI: should link to default episode", () => {
render(
<MemoryRouter>
<Sidebar />
</MemoryRouter>
</MemoryRouter>,
);
const linkElement = screen
.getByText("Resources")
.closest("a")
?.getAttribute("href");
expect(linkElement).toEqual(
expect.stringContaining(`/${DEFAULT_EPISODE}/resources`)
expect.stringContaining(`/${DEFAULT_EPISODE}/resources`),
);
});

test("UI: should collapse sidebar", () => {
render(
<MemoryRouter>
<Sidebar collapsed={true} />
</MemoryRouter>
</MemoryRouter>,
);
expect(screen.queryByText("Home")).toBeNull();
});
Expand All @@ -37,7 +37,7 @@ test("UI: should link to episode in surrounding context", () => {
>
<Sidebar />
</EpisodeContext.Provider>
</MemoryRouter>
</MemoryRouter>,
);
const linkElement = screen
.getByText("Resources")
Expand Down
6 changes: 3 additions & 3 deletions frontend2/src/contexts/CurrentUserContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, useContext } from "react";
import { type UserPrivate } from "../utils/types/model/models";
import { type UserPrivate } from "../utils/types";

export enum AuthStateEnum {
LOADING = "loading",
Expand All @@ -17,15 +17,15 @@ interface CurrentUserContextType {
}

export const CurrentUserContext = createContext<CurrentUserContextType | null>(
null
null,
);

export const useCurrentUser = (): CurrentUserContextType => {
const currentUserContext = useContext(CurrentUserContext);

if (currentUserContext === null) {
throw new Error(
"useCurrentUser has to be used within <CurrentUserContext.Provider>"
"useCurrentUser has to be used within <CurrentUserContext.Provider>",
);
}

Expand Down
4 changes: 2 additions & 2 deletions frontend2/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import "./index.css";
import App from "./App";

const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
document.getElementById("root") as HTMLElement,
);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
</React.StrictMode>,
);
Loading

0 comments on commit 62c7d07

Please sign in to comment.