Skip to content

Commit

Permalink
upgrade to react 18
Browse files Browse the repository at this point in the history
  • Loading branch information
venil7 committed Jul 8, 2024
1 parent bdb93d0 commit 637b797
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 29 deletions.
3 changes: 3 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ http {
server_tokens off;

root /app/static;
location / {
try_files $uri $uri/ /index.html;
}
gzip_static on;
}
}
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"mock": "vite-node -w -c ./src/mocks/vite.config.ts ./src/mocks/index.ts"
},
"dependencies": {
"@preact/signals-react": "^2.1.0",
"@preact/signals-react": "^1.3.8",
"bootstrap": "^5.1.3",
"date-fns": "^2.30.0",
"express": "^4.18.1",
Expand Down
4 changes: 3 additions & 1 deletion src/enhancers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export function withNoData<P extends Props, K extends keyof P>(
) {
return function (Component: React.FC<P>): React.FC<WithNoData<P, K>> {
return (props: WithNoData<P, K>) =>
getter(props) === null ? null : (
getter(props) === null ? (
<>data missing</>
) : (
<Component {...(props as unknown as P)} />
);
};
Expand Down
14 changes: 8 additions & 6 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import "bootstrap/dist/css/bootstrap.min.css";
import React from "react";
import ReactDOM from "react-dom";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { App } from "./components/App";

import "./style/main.scss";

ReactDOM.render(
<React.StrictMode>
const container = document.getElementById("root");
const root = createRoot(container!);

root.render(
<StrictMode>
<div className="container">
<App />
</div>
</React.StrictMode>,
document.getElementById("root")
</StrictMode>
);
1 change: 1 addition & 0 deletions src/screens/CharacterScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Character } from "../components/Character";
export const CharacterScreen: React.FC = () => {
const { character } = useContext(StoreContext);
const { id = 1 } = useParams();

useEffect(() => {
character.load(+id);
}, [character, id]);
Expand Down
2 changes: 1 addition & 1 deletion src/screens/FilmScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Film } from "../components/Film";

export const FilmScreen: React.FC = () => {
const { film } = useContext(StoreContext);

const { id = 1 } = useParams();

useEffect(() => {
film.load(+id);
}, [film, id]);
Expand Down
27 changes: 18 additions & 9 deletions src/service/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ap } from "fp-ts/lib/Identity";
import { chain } from "fp-ts/lib/Task";
import { tryCatch } from "fp-ts/lib/TaskEither";
import { pipe } from "fp-ts/lib/function";
import { pipe, tupled } from "fp-ts/lib/function";
import { AppError, genericError } from "../domain/error";
import { Action, Nullable } from "../domain/util";

Expand All @@ -18,15 +19,23 @@ export const createFetch =
url: string,
body: Nullable<T> = null
): Action<unknown> => {
const fetchTask = pipe(
() => fetch(url, { method, body }),
chain((resp) => () => resp.json())
);
return tryCatch<AppError, unknown>(fetchTask, (e) =>
genericError((e as Error).message)
return tryCatch<AppError, unknown>(
pipe(
() =>
fetch(url, { method, body: body ? JSON.stringify(body) : undefined }),
chain((resp) => () => resp.json())
),
(e) => genericError((e as Error).message)
);
};

export const createGet = (url: string) => createFetch(HttpMethod.Get)(url);
export const createGet = (url: string) =>
pipe(HttpMethod.Get, createFetch, ap(url));

export const createPost = <T extends BodyInit>(url: string, body: T) =>
createFetch(HttpMethod.Post)(url, body);
pipe(
HttpMethod.Post,
createFetch,
tupled,
ap<[string, Nullable<T>]>([url, body])
);
12 changes: 6 additions & 6 deletions src/stores/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ export const createStoreBase = <T>(data: Signal<T>): StoreBase<T> => {
error.value = null;
}),
chain(() => action),
chainFirstIOK((d) => () => {
chainFirstIOK((value) => () => {
fetching.value = false;
data.value = d;
data.value = value;
}),
orElseW((err) =>
fromIO(() => {
orElseW((err) => {
return fromIO(() => {
fetching.value = false;
error.value = err;
})
)
});
})
)();
};

Expand Down

0 comments on commit 637b797

Please sign in to comment.