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

Feature/loading component #56

Merged
merged 7 commits into from
Nov 3, 2023
Merged
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
Binary file added public/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions src/components/Loading/Loading.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { render, screen } from "@testing-library/react";
import Loading from "./Loading";
import { ThemeProvider } from "styled-components";
import mainTheme from "../../styles/mainTheme";
import { BrowserRouter } from "react-router-dom";
import UiContextWrapper from "../../features/Ui/store/UiContextWrapper";

describe("Given a Loading component", () => {
describe("When is render", () => {
test("Then it should show `logo loading page`", () => {
const expectedAltText = "logo loading page";
const expectedImageSrc = "public/images/logo.png";

render(
<BrowserRouter>
<UiContextWrapper>
<ThemeProvider theme={mainTheme}>
<Loading />
</ThemeProvider>
</UiContextWrapper>
</BrowserRouter>,
);

const loadImage = screen.getByAltText(expectedAltText);
expect(loadImage).toHaveAttribute("src", expectedImageSrc);
});
});
});
9 changes: 9 additions & 0 deletions src/components/Loading/Loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Loading = (): React.ReactElement => {
return (
<div>
<img src="public/images/logo.png" alt="logo loading page"></img>
</div>
);
};

export default Loading;
6 changes: 6 additions & 0 deletions src/features/Ui/store/UiContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createContext } from "react";
import UiContextStructure from "./types";

const UiContext = createContext<UiContextStructure>({} as UiContextStructure);

export default UiContext;
13 changes: 13 additions & 0 deletions src/features/Ui/store/UiContextWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import UiContext from "./UiContext";
import { PropsWithChildren, useMemo, useState } from "react";

const UiContextWrapper = ({
children,
}: PropsWithChildren): React.ReactElement => {
const [isLoading, setIsLoading] = useState<boolean>(false);
const uiValue = useMemo(() => ({ isLoading, setIsLoading }), [isLoading]);

return <UiContext.Provider value={uiValue}>{children}</UiContext.Provider>;
};

export default UiContextWrapper;
6 changes: 6 additions & 0 deletions src/features/Ui/store/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface UiContextStructure {
isLoading: boolean;
setIsLoading: (isLoading: boolean) => void;
}

export default UiContextStructure;
19 changes: 11 additions & 8 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import mainTheme from "./styles/mainTheme";
import CharacarterWrapper from "./features/characters/store/CharactersWrapper";
import GlobalStyle from "./styles/GlobalStyle";
import "@fontsource-variable/changa";
import UiContextWrapper from "./features/Ui/store/UiContextWrapper";

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<CharacarterWrapper>
<ThemeProvider theme={mainTheme}>
<BrowserRouter>
<GlobalStyle />
<App />
</BrowserRouter>
</ThemeProvider>
</CharacarterWrapper>
<UiContextWrapper>
<CharacarterWrapper>
<ThemeProvider theme={mainTheme}>
<BrowserRouter>
<GlobalStyle />
<App />
</BrowserRouter>
</ThemeProvider>
</CharacarterWrapper>
</UiContextWrapper>
</React.StrictMode>,
);
1 change: 1 addition & 0 deletions src/styles/mainTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const mainTheme: DefaultTheme = {
mainFont: "#000",
secondaryFont: "#fff",
inputBackground: "#fff",
logoMain: "#FF000",
},
typography: {
mainFontFamily: "Verdana, Geneva, Tahoma, sans-serif",
Expand Down
1 change: 1 addition & 0 deletions src/styles/styled.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare module "styled-components" {
mainFont: string;
secondaryFont: string;
inputBackground: string;
logoMain: string;
};
typography: {
mainFontFamily: string;
Expand Down
Loading