Skip to content

Commit 8302785

Browse files
Merge branch 'main' into bugfix/CG-4432-Sorting-doesnt-work-when-logged-in
# Conflicts: # samples/musicfestival-frontend-react/src/pages/SearchPage.tsx
2 parents 14e08a2 + 408ec2a commit 8302785

File tree

4 files changed

+99
-106
lines changed

4 files changed

+99
-106
lines changed

samples/musicfestival-frontend-react/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"@graphql-codegen/typescript": "^2.7.3",
1010
"@graphql-codegen/typescript-operations": "^2.5.3",
1111
"@graphql-codegen/typescript-react-query": "^4.0.1",
12-
"@mui/material": "^5.13.3",
1312
"@tanstack/react-query": "^4.6.0",
1413
"@testing-library/jest-dom": "^5.14.1",
1514
"@testing-library/react": "^13.0.0",

samples/musicfestival-frontend-react/src/App.css

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/musicfestival-frontend-react/src/components/SearchButton.tsx

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,87 +4,74 @@ import { ArtistAutocompleteQuery, useArtistAutocompleteQuery } from "../generate
44
import { generateGQLSearchQueryVars } from "../helpers/queryCacheHelper";
55
import { isEditOrPreviewMode } from "../helpers/urlHelper";
66

7-
const singleKeyUrl = process.env.REACT_APP_CONTENT_GRAPH_GATEWAY_URL as string
8-
97
type CustomString = string | number | readonly string[] | undefined
108

11-
function SearchButton(): JSX.Element {
9+
function SearchButton({filterValue}: any): JSX.Element {
10+
const singleKeyUrl = process.env.REACT_APP_CONTENT_GRAPH_GATEWAY_URL as string
11+
const ARTIST = "Artist"
1212
const [searchParams] = useSearchParams()
1313
const [token, setToken] = useState("")
1414
const [isShown, setIsShown] = useState(false)
15-
const [searchValue, setSearchValue] = useState<CustomString>(searchParams.get("q")?.toString())
16-
const [orderBy, setOrderBy] = useState("ASC")
17-
let variables: any = generateGQLSearchQueryVars(token, window.location.pathname, searchValue as string | null, orderBy);
18-
const modeEdit = isEditOrPreviewMode()
19-
let stringArr: (string | null)[] = []
20-
15+
const [searchValue, setSearchValue] = useState<CustomString>(searchParams.get("q")?.toString() ?? "")
16+
const [orderBy] = useState("ASC")
2117
let autocompleteData : ArtistAutocompleteQuery | undefined = undefined
18+
19+
let modeEdit = isEditOrPreviewMode()
20+
let variables = generateGQLSearchQueryVars(token, window.location.pathname, searchValue as string | null, orderBy);
2221
const { data : artistAutocompleteData } = useArtistAutocompleteQuery({ endpoint: singleKeyUrl }, variables, { staleTime: 2000, enabled: !modeEdit || !!token })
2322
autocompleteData = artistAutocompleteData
2423

2524
function search(event: any, action: string){
2625
if ((action == "keypress" && event.charCode === 13) || action == "buttonclick") {
27-
window.location.href = `${window.location.origin}/search?q=${searchValue}`
26+
window.location.href = `${window.location.origin}/search?q=${searchValue}&f=${filterValue ?? ARTIST}`
2827
}
2928
}
3029

3130
function onValueChange(event: any){
3231
setSearchValue(event.target.value);
33-
event.target.value != "" && event.target.value !== undefined ? setIsShown(true) : setIsShown(false);
32+
event.target.value !== undefined ? setIsShown(true) : setIsShown(false);
3433
}
3534

3635
function onAutoClick(event: any){
3736
setSearchValue(event.target.textContent);
38-
window.location.href = `${window.location.origin}/search?q=${event.target.textContent}`
37+
window.location.href = `${window.location.origin}/search?q=${event.target.textContent}&f=${filterValue ?? ARTIST}`
3938
}
4039

4140
return (
4241
<div>
43-
<div className="nav-table-cell">
44-
<input className="search-input" type="text" id="search-input" placeholder="Search"
45-
onKeyPress={(event) => {search(event, 'keypress')}} value={searchValue} onChange={onValueChange} />
46-
<a className="search-icon" onClick={(event) => {search(event, 'buttonclick')}}>
47-
<i className="fa fa-search"></i>
48-
</a>
49-
50-
{/* <Autocomplete
51-
sx={{
52-
display: 'inline-block',
53-
'& input': {
54-
width: 200,
55-
bgcolor: 'background.paper',
56-
color: (theme) =>
57-
theme.palette.getContrastText(theme.palette.background.paper),
58-
},
59-
}}
60-
id="custom-input-demo"
61-
options={stringArr}
62-
renderInput={(params) => (
63-
<div ref={params.InputProps.ref}>
64-
<input className="search-input" type="text" id="search-input" placeholder="Search"
65-
onKeyPress={(event) => {search(event, 'keypress')}} value={searchValue} onChange={onValueChange} {...params.inputProps} />
42+
<div className="nav-table-cell autocomplete">
43+
<input className="search-input"
44+
type="text"
45+
id="search-input"
46+
placeholder="Search"
47+
onKeyPress={(event) => {search(event, 'keypress')}}
48+
value={searchValue}
49+
onChange={onValueChange}
50+
onFocus={() => setIsShown(true)}
51+
onBlur={() =>
52+
setTimeout(() => {
53+
setIsShown(false);
54+
}, 150)
55+
} />
6656
<a className="search-icon" onClick={(event) => {search(event, 'buttonclick')}}>
6757
<i className="fa fa-search"></i>
6858
</a>
69-
</div>
70-
)}
71-
/> */}
72-
<div className="autocomplete-block" style={isShown ? {display: "inherit"}: {display: "none"}}>
73-
{
74-
autocompleteData?.ArtistDetailsPage?.autocomplete?.ArtistName?.map((name) => {
75-
return(
76-
<div key={name} onClick={(event) => onAutoClick(event)}>{name}</div>
77-
)
78-
})
79-
}
80-
{
81-
autocompleteData?.ArtistDetailsPage?.autocomplete?.StageName?.map((name) => {
82-
return(
83-
<div key={name} onClick={(event) => onAutoClick(event)}>{name}</div>
84-
)
85-
})
86-
}
87-
</div>
59+
<div className="autocomplete-block" style={isShown ? {display: "inherit"}: {display: "none"}}>
60+
{
61+
autocompleteData?.ArtistDetailsPage?.autocomplete?.ArtistName?.map((name, idx) => {
62+
return(
63+
<div key={idx} onClick={(event) => onAutoClick(event)}>{name}</div>
64+
)
65+
})
66+
}
67+
{
68+
autocompleteData?.ArtistDetailsPage?.autocomplete?.StageName?.map((name, idx) => {
69+
return(
70+
<div key={idx} onClick={(event) => onAutoClick(event)}>{name}</div>
71+
)
72+
})
73+
}
74+
</div>
8875
</div>
8976
</div>
9077
);

0 commit comments

Comments
 (0)