Skip to content

Commit

Permalink
Feature/fg 37 (#742)
Browse files Browse the repository at this point in the history
* changed sizing of overall page containers to be more consistant

* made a page for 'expo sjef' to view all pictures that is considered good for posting on instagram

* done with expo page, grid of all good images with possibility to select and download pictures

* fixed jzip and file-saver import

* changed the api requests to get allPictures

* made the page more responsive

* fixed problem with key identifer

* mini fix

* mini fix2

* fixed problem

* fixed code smells

* fixed code smells

* fixed code smells

* made sonar ignore line with math.random

* removed duplicate folder

* to remove duplicate code, i made a image context for the lightbox, so we can open it from everywhere a picture is

* mooo mooo code smell fix

* mooo mooo code smell fix

* created a text showing up if no images

---------

Co-authored-by: endre2112 <[email protected]>
  • Loading branch information
SimpChip and endre2112 authored Aug 18, 2023
1 parent 15c18dd commit cf353c9
Show file tree
Hide file tree
Showing 13 changed files with 630 additions and 203 deletions.
370 changes: 232 additions & 138 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
"axios": "0.27.2",
"classnames": "2.3.2",
"date-fns": "^2.29.3",
"file-saver": "^2.0.5",
"form-data": "4.0.0",
"formik": "^2.2.9",
"husky": "7.0.4",
"jszip": "^3.10.1",
"react": "17.0.2",
"react-context": "0.0.3",
"react-dom": "17.0.2",
Expand All @@ -61,6 +63,7 @@
"@babel/core": "^7.19.3",
"@babel/types": "7.19.3",
"@types/classnames": "2.3.1",
"@types/file-saver": "^2.0.5",
"@types/lodash": "^4.14.186",
"@types/react": "^17.0.39",
"@types/react-dom": "17.0.11",
Expand Down
8 changes: 6 additions & 2 deletions src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import Motives from "./views/Intern/Motives/Motives";
import LoggInn from "./views/Intern/LoggInn/LoggInn";
import EditMotive from "./views/Intern/EditMotive/EditMotive";
import InternNav from "./views/Intern/InternNav/InternNav";
import Expo from "./views/Intern/Expo/Expo";
import Redirect from "./utils/Redirect/Redirect";
import MotiveHeader from "./components/ImageViewer/MotiveHeader";
import { Box } from "@mui/material";

const AppRoutes: FC = () => {
return (
<>
<Box sx={{ m: "1rem" }}>
<Routes>
<Route path="/" element={<App />} />
<Route path="/motive/:id" element={<MotiveHeader />} />
Expand All @@ -30,8 +32,10 @@ const AppRoutes: FC = () => {
<Route path="/intern/arkivsjef" element={<Arkivsjef />} />
<Route path="/intern/motive" element={<Motives />} />
<Route path="/intern/motive/:id" element={<EditMotive />} />
<Route path="/intern/expo" element={<Expo />} />
<Route path="/logg-inn" element={<LoggInn />} />
<Route path="/intern" element={<InternNav />} />

<Route path="*" element={<NotFound />} />
<Route
path="/samf-wiki"
Expand All @@ -52,7 +56,7 @@ const AppRoutes: FC = () => {
element={<Redirect link="https://github.com/Fotogjengen/" />}
/>
</Routes>
</>
</Box>
);
};

Expand Down
12 changes: 2 additions & 10 deletions src/components/Header/Header.module.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
.nav {
margin-top: 2rem;
margin-bottom: 1rem;
}

.navHead {
margin-bottom: 1rem;
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 1rem;
padding-bottom: 0.5rem;
padding-right: 0.5rem;
}

.hamburger {
Expand Down Expand Up @@ -38,8 +33,6 @@
align-items: center;
justify-content: space-between;
width: 90vw;
margin: 1rem 0rem;
padding: 0.2rem 0.6rem;
box-shadow: rgba(0, 0, 0, 0.4) 0px 2px 3px 0px;

}
Expand All @@ -49,7 +42,6 @@
}

.navContainer {
margin: 1rem;
font-size: 1.5rem;
display: none;
grid-template-columns: 8fr 2fr;
Expand Down
25 changes: 4 additions & 21 deletions src/components/ImageViewer/GridImageViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import React, { FC, useState } from "react";
import React, { FC, useContext } from "react";
import styles from "./imageStyle.module.css";
import MotiveImage from "./MotiveImage";
import Lightbox from "react-image-lightbox";
import "react-image-lightbox/style.css";
import { PhotoDto } from "../../../generated";
import { createImgUrl } from "../../utils/createImgUrl/createImgUrl";
import { ImageContext } from "../../contexts/ImageContext";

interface Props {
photos: PhotoDto[];
}

const ShowMotive: FC<Props> = ({ photos }) => {
const [isOpen, setIsOpen] = useState(false);
const [photoIndex, setPhotoIndex] = useState(0);

const { setPhotos, setPhotoIndex, setIsOpen } = useContext(ImageContext);
const updateIndex = (index: number) => {
setPhotos(photos);
setPhotoIndex(index);
setIsOpen(true);
};
Expand Down Expand Up @@ -47,22 +46,6 @@ const ShowMotive: FC<Props> = ({ photos }) => {
</div>
</div>
</div>
{isOpen && (
<Lightbox
mainSrc={createImgUrl(photos[photoIndex])}
nextSrc={createImgUrl(photos[(photoIndex + 1) % photos.length])}
prevSrc={createImgUrl(
photos[(photoIndex + photos.length - 1) % photos.length],
)}
onCloseRequest={() => setIsOpen(false)}
onMovePrevRequest={() =>
setPhotoIndex((photoIndex + photos.length - 1) % photos.length)
}
onMoveNextRequest={() =>
setPhotoIndex((photoIndex + 1) % photos.length)
}
/>
)}
</>
);
};
Expand Down
89 changes: 89 additions & 0 deletions src/components/ImageViewer/ShowGoodMotive.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React, { FC, useState, useEffect, useContext } from "react";
import MotiveImage from "./MotiveImage";
import "react-image-lightbox/style.css";
import { MotiveDto, PhotoDto } from "../../../generated";
import { MotiveApi } from "../../utils/api/MotiveApi";
import { PhotoApi } from "../../utils/api/PhotoApi";
import { createImgUrl } from "../../utils/createImgUrl/createImgUrl";
import {
Accordion,
AccordionDetails,
AccordionSummary,
Grid,
Typography,
} from "@mui/material";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import { ImageContext } from "../../contexts/ImageContext";

interface Props {
id: string;
index: number;
}

const ShowGoodMotive: FC<Props> = ({ id, index }: Props) => {
const [photoResponse, setPhotoResponse] = useState<PhotoDto[]>([]);
const [motiveResponse, setMotiveResponse] = useState<MotiveDto>(
{} as MotiveDto,
);

const { setPhotos, setPhotoIndex, setIsOpen } = useContext(ImageContext);

const bgcolors = ["#da7777", "#f3ee78", "#9c77da", "#BADA77", "#7793da"];

const updateIndex = (index: number) => {
setPhotos(photoResponse);
setPhotoIndex(index);
setIsOpen(true);
};

const imageItems = photoResponse.map((image: PhotoDto, index: number) => {
const key = `is-good-picture-${index}`;
return (
<Grid key={key} item>
<MotiveImage
id={image.photoId.id}
image={createImgUrl(image)}
imageListProp={photoResponse}
index={index}
updateIndex={() => updateIndex(index)}
title={image.motive.title}
/>
</Grid>
);
});

useEffect(() => {
if (id) {
MotiveApi.getById(id)
.then((res) => setMotiveResponse(res))
.catch((e) => console.log(e));
PhotoApi.getAll()
.then((res) => setPhotoResponse(res))
.catch((e) => console.log(e));
}
}, []);

return (
<>
{photoResponse.length != 0 && (
<Accordion>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel1a-content"
id="panel1a-header"
sx={{ boxShadow: 1, bgcolor: bgcolors[index % bgcolors.length] }}
>
<Typography>
{motiveResponse.title} | {motiveResponse.dateCreated}
</Typography>
</AccordionSummary>
<AccordionDetails>
<Grid container>{imageItems}</Grid>
</AccordionDetails>
</Accordion>
)}
</>
);
};

export default ShowGoodMotive;
2 changes: 0 additions & 2 deletions src/components/ImageViewer/imageStyle.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
height: 200px;
width: 300px;
box-shadow: 0px 4px 4px 0px rgba(0,0,0, 0.25);
padding: 0px;
margin: 10px;
background-color: #F3F3F3;
}

Expand Down
17 changes: 17 additions & 0 deletions src/contexts/ImageContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createContext, Dispatch, SetStateAction } from "react";
import { PhotoDto } from "../../generated";



interface IImageContext {
isOpen: boolean;
photoIndex: number;
setIsOpen: Dispatch<SetStateAction<boolean>>;
setPhotoIndex: Dispatch<SetStateAction<number>>;
photos: PhotoDto[],
setPhotos: Dispatch<SetStateAction<Array<PhotoDto>>>
}

const defaultState = {} as IImageContext;

export const ImageContext = createContext<IImageContext>(defaultState);
4 changes: 0 additions & 4 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@ html {
margin: 0 !important;
}

.container {
width: 90vw;
margin: auto;
}
80 changes: 57 additions & 23 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@ import { render } from "react-dom";
import "./index.css";
import AppRoutes from "./AppRoutes";
import { BrowserRouter as Router } from "react-router-dom";
import { ThemeProvider } from "@mui/material";
import guistyles from "./styles/utilities.module.css";
import { Box, ThemeProvider } from "@mui/material";
import { GuiFooter } from "./gui-components";
import HeaderComponent from "./components/Header/Header";
import { theme } from "./styles/muiStyles";
import { Auth0Provider } from "@auth0/auth0-react";
import { AlertContext, severityEnum } from "./contexts/AlertContext";
import { ImageContext } from "./contexts/ImageContext";
import Alert from "./components/Alert/Alert";
import Lightbox from "react-image-lightbox";
import { PhotoDto } from "../generated";
import { createImgUrl } from "./utils/createImgUrl/createImgUrl";

const Root: FC = () => {
// Hooks for the Alert component
const [open, setOpen] = useState(false);
const [message, setMessage] = useState("");
const [severity, setSeverity] = useState(severityEnum.INFO);

const [photos, setPhotos] = useState<PhotoDto[]>([]);
const [isOpen, setIsOpen] = useState(false);
const [photoIndex, setPhotoIndex] = useState(0);

return (
<>
<Auth0Provider
Expand All @@ -26,34 +33,61 @@ const Root: FC = () => {
redirectUri={window.location.origin}
>
<ThemeProvider theme={theme}>
<AlertContext.Provider
<ImageContext.Provider
value={{
open,
setOpen,
setMessage,
message,
setSeverity,
severity,
isOpen,
setIsOpen,
photoIndex,
setPhotoIndex,
photos,
setPhotos,
}}
>
{open ? (
<Alert
open={open}
setOpen={setOpen}
message={message}
severity={severity}
/>
) : null}
<div className={guistyles.container}>
<div className={"container"}>
<AlertContext.Provider
value={{
open,
setOpen,
setMessage,
message,
setSeverity,
severity,
}}
>
{open ? (
<Alert
open={open}
setOpen={setOpen}
message={message}
severity={severity}
/>
) : null}
<Box sx={{ m: "2rem" }}>
<Router>
<HeaderComponent />
<AppRoutes />
</Router>
</div>
</div>
<GuiFooter />
</AlertContext.Provider>
</Box>
<GuiFooter />
</AlertContext.Provider>
{isOpen && (
<Lightbox
mainSrc={createImgUrl(photos[photoIndex])}
nextSrc={createImgUrl(photos[(photoIndex + 1) % photos.length])}
prevSrc={createImgUrl(
photos[(photoIndex + photos.length - 1) % photos.length],
)}
onCloseRequest={() => setIsOpen(false)}
onMovePrevRequest={() =>
setPhotoIndex(
(photoIndex + photos.length - 1) % photos.length,
)
}
onMoveNextRequest={() =>
setPhotoIndex((photoIndex + 1) % photos.length)
}
/>
)}
</ImageContext.Provider>
</ThemeProvider>
</Auth0Provider>
</>
Expand Down
Loading

0 comments on commit cf353c9

Please sign in to comment.