2020-12-03 18:29:47 +01:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import LbcSymbol from 'component/common/lbc-symbol';
|
|
|
|
import WunderbarSuggestion from 'component/wunderbarSuggestion';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
winningUri: ?string,
|
|
|
|
doResolveUris: (Array<string>) => void,
|
2020-12-03 21:42:41 +01:00
|
|
|
uris: Array<string>,
|
|
|
|
resolvingUris: boolean,
|
2021-09-18 16:23:30 +02:00
|
|
|
preferEmbed: boolean,
|
2020-12-03 18:29:47 +01:00
|
|
|
};
|
|
|
|
|
2020-12-03 21:42:41 +01:00
|
|
|
export default function WunderbarTopSuggestion(props: Props) {
|
2021-09-18 16:23:30 +02:00
|
|
|
const { uris, resolvingUris, winningUri, doResolveUris, preferEmbed } = props;
|
2020-12-03 18:29:47 +01:00
|
|
|
|
2020-12-03 21:42:41 +01:00
|
|
|
const stringifiedUris = JSON.stringify(uris);
|
2020-12-03 18:29:47 +01:00
|
|
|
React.useEffect(() => {
|
2020-12-03 21:42:41 +01:00
|
|
|
if (stringifiedUris) {
|
|
|
|
const arrayUris = JSON.parse(stringifiedUris);
|
2020-12-03 18:29:47 +01:00
|
|
|
|
2020-12-03 21:42:41 +01:00
|
|
|
if (arrayUris.length > 0) {
|
|
|
|
doResolveUris(arrayUris);
|
|
|
|
}
|
2020-12-03 18:29:47 +01:00
|
|
|
}
|
2020-12-03 21:42:41 +01:00
|
|
|
}, [doResolveUris, stringifiedUris]);
|
2020-12-03 18:29:47 +01:00
|
|
|
|
2020-12-03 21:42:41 +01:00
|
|
|
if (resolvingUris) {
|
|
|
|
return (
|
|
|
|
<div className="wunderbar__winning-claim">
|
|
|
|
<div className="wunderbar__label wunderbar__placeholder-label" />
|
|
|
|
|
|
|
|
<div className="wunderbar__suggestion wunderbar__placeholder-suggestion">
|
|
|
|
<div className="wunderbar__placeholder-thumbnail" />
|
|
|
|
<div className="wunderbar__placeholder-info" />
|
|
|
|
</div>
|
|
|
|
<hr className="wunderbar__top-separator" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2020-12-03 18:29:47 +01:00
|
|
|
|
2021-09-18 16:23:30 +02:00
|
|
|
if (!winningUri || preferEmbed) {
|
2020-12-03 18:29:47 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2020-12-03 22:06:54 +01:00
|
|
|
<div className="wunderbar__label">
|
|
|
|
<LbcSymbol prefix={__('Most Supported')} />
|
|
|
|
</div>
|
2020-12-03 18:29:47 +01:00
|
|
|
|
2020-12-03 22:06:54 +01:00
|
|
|
<WunderbarSuggestion uri={winningUri} />
|
2020-12-03 18:29:47 +01:00
|
|
|
<hr className="wunderbar__top-separator" />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|