Skip to content

Commit

Permalink
Feature/fg 101 (#794)
Browse files Browse the repository at this point in the history
* fått enkel innlogging til å funke

* fått create user til å funke ish

* fixed login in header

* unstable finished

* change api endpoint fro  8080 to 8000

* kommentert ut litt kode som skal brukes senere.

* updated browser-list-db because azure static check asked me to do so

* added linebreak to run azure static web apps i github

* lagt til createUser komponent

* Det funker plz!

* Lagt til knapp til å komme seg tilbake til arkivsjef side

* Lagt til input for fornavn og etternav,endret på styling også

* begynt på side for endring av photgangbangers

* FIX AZURE error lol

* lagt til mulighet til å redigere info til en photogangbanger

* Fikset og stylet redigeringSide, kan nå trykke på switch for om bruker er pang og eller aktiv

* Slettet noen console logs

* Fjerne enda none til console logs

* Dummy commit

* oppdatert Azure/msal/browser

* Endret noen små feil

* slettet kommentar

* Endret på utsende på gridImageViewer, ser litt bedre ut nå

* Gjorde rammene rundt bildene litt tynnere

* Kan nå søke gjennom suggestions

* kan nå søke ved å trykke enter, eller trykke på søke knappen

* sonar cloud endringer

* Oppdatert msal

* Tester med å gjøre en liten endring

* Fjernet noen imports som ikke ble brukt

---------

Co-authored-by: Marius Bølset Gisleberg <[email protected]>
  • Loading branch information
PTB03 and Gissebass authored Apr 6, 2024
1 parent d8a8a0b commit 751717e
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 24 deletions.
30 changes: 15 additions & 15 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 @@ -31,7 +31,7 @@
},
"dependencies": {
"@auth0/auth0-react": "^1.11.0",
"@azure/msal-browser": "^3.10.0",
"@azure/msal-browser": "^3.11.1",
"@azure/msal-react": "^2.0.8",
"@date-io/date-fns": "^1.3.13",
"@emotion/react": "^11.10.4",
Expand Down
12 changes: 11 additions & 1 deletion src/components/ImageViewer/GridImageViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ import "react-image-lightbox/style.css";
import { PhotoDto } from "../../../generated";
import { createImgUrl } from "../../utils/createImgUrl/createImgUrl";
import { ImageContext } from "../../contexts/ImageContext";
import { useSearchContext } from "../../views/Search/SearchProvider";

interface Props {
photos: PhotoDto[];
}

const ShowMotive: FC<Props> = ({ photos }) => {
const { setPhotos, setPhotoIndex, setIsOpen } = useContext(ImageContext);

const searchContext = useSearchContext();
const searchQuery = searchContext ? searchContext.searchQuery : "";




const filteredPhotos = photos.filter((photo: PhotoDto) => searchQuery != "" ? (photo.motive.title.toLowerCase().includes(searchQuery.toLowerCase())) : photos); //Finn en bedre løsning etterhvert

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

const imageItems = photos.map((image: PhotoDto, index: number) => {
const imageItems = filteredPhotos.map((image: PhotoDto, index: number) => {
const key = `motive-image${index}`;
return (
<MotiveImage
Expand Down
8 changes: 5 additions & 3 deletions src/components/SearchComponent/Search.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
.suggestions {
background-color: #f0f0f0;
border: 1px solid #a0a0a0;
border-radius: 1px;
border-radius: 5px;
position: absolute;
}

.suggestions:hover {
Expand All @@ -16,6 +17,7 @@

.suggestionBox {
background-color: white;
border-radius: 1px;
border: 1px solid #a0a0a0;
border-bottom: #a0a0a0 1px solid;
position: relative;

}
29 changes: 25 additions & 4 deletions src/components/SearchComponent/SearchField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ import React, { FC, useEffect, useMemo, useState } from "react";
import { IconButton, InputAdornment, MenuItem, TextField } from "@mui/material";
import SearchIcon from "@mui/icons-material/Search";
import { SearchSuggestionsApi } from "../../utils/api/searchSuggestionsApi";
import styles from "./Search.module.css";
import { useSearchContext } from "../../views/Search/SearchProvider";


const SearchField: FC = () => {
const [search, setSearch] = useState("");
const [suggestions, setSuggestions] = useState<string[]>([]);

const searchContext = useSearchContext();
const setSearchQuery = searchContext ? searchContext.setSearchQuery : () => {console.error("Search is context not available"); };


const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSearch(event.target.value);
};
Expand Down Expand Up @@ -36,34 +43,48 @@ const SearchField: FC = () => {

const suggestionBoxes = useMemo(() => {
return suggestions.map((s, key) => (
<MenuItem value={s} key={key} color="" onClick={() => handleSearch(s)}>
<MenuItem className={styles.suggestionBox} value={s} key={key} color="" onClick={() => handleSearch(s)}>
{s}
</MenuItem>
));
}, [suggestions]);

const handleSearch = (s: string) => {
return s;
setSearch(s)
setSearchQuery(s)
//Send s to a different component
};

const enterSearch = (event: React.KeyboardEvent<HTMLDivElement>) => {
if (event.key === 'Enter') {
console.log(search)
setSearchQuery(search);

}
}



return (
<div>
<TextField
label={placeholder}
value={search}
fullWidth
variant="outlined"
onChange={handleChange}
onKeyPress={enterSearch}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton>
<IconButton onClick={() => setSearchQuery(search)}>
<SearchIcon />
</IconButton>
</InputAdornment>
),
}}
/>
<div>{suggestionBoxes}</div>
<div className={styles.suggestions}>{suggestionBoxes}</div>
</div>
);
};
Expand Down
9 changes: 9 additions & 0 deletions src/views/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ import React from "react";
import SearchField from "../../components/SearchComponent/SearchField";
import SearchPhotoGrid from "./SearchPhotoGrid";
import styles from "./Searchbar.module.css";
import SearchProvider from "./SearchProvider";



const Search = () => {




return (
<SearchProvider>
<div>
<div className={styles.backgroundFlex} style={{backgroundColor: "white"}}>
<SearchField />
Expand All @@ -14,6 +22,7 @@ const Search = () => {
<SearchPhotoGrid />
</div>
</div>
</SearchProvider>
);
};

Expand Down
23 changes: 23 additions & 0 deletions src/views/Search/SearchProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { useState } from 'react'
import { useContext, createContext } from 'react';

export interface SearchContextType {
searchQuery: string;
setSearchQuery: React.Dispatch<React.SetStateAction<string>>;
}


const SearchContext = createContext<SearchContextType | undefined>(undefined);

export const useSearchContext = () => useContext(SearchContext);

const SearchProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [searchQuery, setSearchQuery] = useState<string>("");
return (
<SearchContext.Provider value={{ searchQuery, setSearchQuery }}>
{children}
</SearchContext.Provider>
);
};

export default SearchProvider

0 comments on commit 751717e

Please sign in to comment.