Add onClick event to Other results cards
This commit is contained in:
parent
a5ed4f84f6
commit
2b415b5189
@ -71,6 +71,10 @@ export default function App() {
|
|||||||
setSelected(true);
|
setSelected(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
console.log('click')
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// TODO optimize re-rendering, probably by using onCompleted instead of this useEffect
|
// TODO optimize re-rendering, probably by using onCompleted instead of this useEffect
|
||||||
// See https://github.com/apollographql/apollo-client/issues/5268#issuecomment-596950174
|
// See https://github.com/apollographql/apollo-client/issues/5268#issuecomment-596950174
|
||||||
@ -97,7 +101,7 @@ export default function App() {
|
|||||||
suggestions={suggestions}
|
suggestions={suggestions}
|
||||||
handleSelect={handleSelect}
|
handleSelect={handleSelect}
|
||||||
/>
|
/>
|
||||||
{selected && <Results artists={artists} />}
|
{selected && <Results artists={artists} handleClick={handleClick}/>}
|
||||||
</Grommet>
|
</Grommet>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,23 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Box, Heading, Image } from 'grommet';
|
import { Box, Heading } from 'grommet';
|
||||||
|
|
||||||
export const Other = ({ image, name }: { image: string; name: string }) => {
|
export const Other = ({
|
||||||
|
image,
|
||||||
|
name,
|
||||||
|
handleClick,
|
||||||
|
}: {
|
||||||
|
image: string;
|
||||||
|
name: string;
|
||||||
|
handleClick: ((...args: any[]) => any) & ((event: MouseEvent) => void);
|
||||||
|
}) => {
|
||||||
return (
|
return (
|
||||||
<Box round='xxsmall' overflow='hidden' align='center' pad='small'>
|
<Box
|
||||||
|
round='xxsmall'
|
||||||
|
overflow='hidden'
|
||||||
|
align='center'
|
||||||
|
pad='small'
|
||||||
|
onClick={handleClick}
|
||||||
|
>
|
||||||
<Heading
|
<Heading
|
||||||
level='4'
|
level='4'
|
||||||
margin={{ bottom: 'small', top: 'small', left: 'small' }}
|
margin={{ bottom: 'small', top: 'small', left: 'small' }}
|
||||||
|
@ -5,7 +5,13 @@ import { Album } from './Album';
|
|||||||
import { Artists } from '../interfaces';
|
import { Artists } from '../interfaces';
|
||||||
import { Other } from './Other';
|
import { Other } from './Other';
|
||||||
|
|
||||||
export const Results = ({ artists }: { artists: Artists }) => {
|
export const Results = ({
|
||||||
|
artists,
|
||||||
|
handleClick,
|
||||||
|
}: {
|
||||||
|
artists: Artists;
|
||||||
|
handleClick: ((...args: any[]) => any) & ((event: MouseEvent) => void);
|
||||||
|
}) => {
|
||||||
const {
|
const {
|
||||||
name: selectedName,
|
name: selectedName,
|
||||||
image: selectedImage,
|
image: selectedImage,
|
||||||
@ -32,10 +38,7 @@ export const Results = ({ artists }: { artists: Artists }) => {
|
|||||||
>
|
>
|
||||||
{selectedName}
|
{selectedName}
|
||||||
</Heading>
|
</Heading>
|
||||||
<Grid
|
<Grid gridArea='artist' margin={{ bottom: 'medium' }}>
|
||||||
gridArea='artist'
|
|
||||||
margin={{ bottom: 'medium' }}
|
|
||||||
>
|
|
||||||
<Box
|
<Box
|
||||||
round='full'
|
round='full'
|
||||||
background={{
|
background={{
|
||||||
@ -52,7 +55,7 @@ export const Results = ({ artists }: { artists: Artists }) => {
|
|||||||
gridArea='other-title'
|
gridArea='other-title'
|
||||||
margin={{ vertical: 'none' }}
|
margin={{ vertical: 'none' }}
|
||||||
alignSelf='end'
|
alignSelf='end'
|
||||||
size="small"
|
size='small'
|
||||||
>
|
>
|
||||||
Other results
|
Other results
|
||||||
</Heading>
|
</Heading>
|
||||||
@ -64,6 +67,7 @@ export const Results = ({ artists }: { artists: Artists }) => {
|
|||||||
key={artist.id}
|
key={artist.id}
|
||||||
image={artist.image}
|
image={artist.image}
|
||||||
name={artist.name}
|
name={artist.name}
|
||||||
|
handleClick={handleClick}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
|
Loading…
Reference in New Issue
Block a user