Add Results component with basic structure
This commit is contained in:
parent
ce1bd7de40
commit
84e86f170e
@ -26,13 +26,13 @@ const QUERY_ARTIST_ALBUMS = gql`
|
|||||||
export default function App() {
|
export default function App() {
|
||||||
const [inputValue, setInputValue] = useState('');
|
const [inputValue, setInputValue] = useState('');
|
||||||
const [getArtists, { data }] = useLazyQuery(QUERY_ARTIST_ALBUMS);
|
const [getArtists, { data }] = useLazyQuery(QUERY_ARTIST_ALBUMS);
|
||||||
const [artists, setArtists] = useState<Artists | undefined>(undefined);
|
const [artists, setArtists] = useState<Artists>(undefined);
|
||||||
const [suggestions, setSuggestions] = useState<string[] | undefined>(
|
const [suggestions, setSuggestions] = useState<string[] | undefined>(
|
||||||
undefined,
|
undefined,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Debounce the database query
|
// Debounce the database query
|
||||||
// See: https://archive.is/wip/6JDqb
|
// Based on: https://archive.is/wip/6JDqb
|
||||||
const updateQuery = () => {
|
const updateQuery = () => {
|
||||||
getArtists({ variables: { byName: inputValue } });
|
getArtists({ variables: { byName: inputValue } });
|
||||||
};
|
};
|
||||||
@ -49,8 +49,9 @@ export default function App() {
|
|||||||
return delayedQuery.cancel;
|
return delayedQuery.cancel;
|
||||||
}, [inputValue, delayedQuery]);
|
}, [inputValue, delayedQuery]);
|
||||||
|
|
||||||
// TODO: Maybe merge the two use effects?
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// TODO optimize rendering, probably by using onCompleted instead of this useEffect
|
||||||
|
// See https://github.com/apollographql/apollo-client/issues/5268#issuecomment-596950174
|
||||||
if (data && data.queryArtists !== []) {
|
if (data && data.queryArtists !== []) {
|
||||||
// Limit artists to 5
|
// Limit artists to 5
|
||||||
const updatedArtists = data.queryArtists.slice(0, 5);
|
const updatedArtists = data.queryArtists.slice(0, 5);
|
||||||
@ -74,7 +75,7 @@ export default function App() {
|
|||||||
handleChange={handleChange}
|
handleChange={handleChange}
|
||||||
suggestions={suggestions}
|
suggestions={suggestions}
|
||||||
/>
|
/>
|
||||||
<Results />
|
<Results artists={artists}/>
|
||||||
</Grommet>
|
</Grommet>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,32 @@
|
|||||||
import React, { PropsWithChildren } from 'react';
|
import React from 'react';
|
||||||
import { Box } from 'grommet';
|
import { Box, Grid } from 'grommet';
|
||||||
|
|
||||||
export const Results = (props: PropsWithChildren<{}>) => {
|
import { Artists } from '../interfaces';
|
||||||
return (
|
|
||||||
<Box
|
export const Results = ({ artists }: { artists: Artists }) => {
|
||||||
as='section'
|
console.log('artists', artists);
|
||||||
direction='row'
|
|
||||||
justify='center'
|
return artists ? (
|
||||||
margin={{ vertical: 'large' }}
|
<Grid
|
||||||
|
rows={['small', 'small']}
|
||||||
|
columns={['1/4', '3/4']}
|
||||||
|
gap='small'
|
||||||
|
areas={[
|
||||||
|
['artist', 'similar'],
|
||||||
|
['discography', 'discography'],
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
</Box>
|
<Box gridArea='artist' background='light-5'>
|
||||||
|
Artist
|
||||||
|
</Box>
|
||||||
|
<Box gridArea='similar' background='light-2'>
|
||||||
|
Similar
|
||||||
|
</Box>
|
||||||
|
<Box gridArea='discography' background='brand'>
|
||||||
|
discography
|
||||||
|
</Box>
|
||||||
|
</Grid>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -11,4 +11,4 @@ export interface Artist {
|
|||||||
albums: Album[];
|
albums: Album[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Artists = Artist[];
|
export type Artists = Artist[] | undefined;
|
Loading…
Reference in New Issue
Block a user