import * as React from 'react'; import { Metadata, MetadataLoadState } from '../checkin'; import * as classNames from 'classnames'; type Suggestion = { name: string; used: boolean; }; type MetadataPreviewProps = { state: MetadataLoadState; metadata: Metadata | null; tags: string[]; handleAddTag: (tag: string) => void; }; const MetadataLoading = () => (
オカズの情報を読み込んでいます…
); const MetadataLoadFailed = () => (
オカズの情報を読み込めませんでした
); export const MetadataPreview: React.FC = ({ state, metadata, tags, handleAddTag }) => { if (state === MetadataLoadState.Inactive) { return null; } const hasImage = metadata !== null && metadata.image !== ''; const descClasses = classNames({ 'col-8': hasImage, 'col-12': !hasImage, }); const tagClasses = (s: Suggestion) => classNames({ 'list-inline-item': true, badge: true, 'badge-primary': !s.used, 'badge-secondary': s.used, 'metadata-tag-item': true, }); const suggestions = metadata?.tags.map((t) => ({ name: t.name, used: tags.indexOf(t.name) !== -1, })) ?? []; return (
{state === MetadataLoadState.Loading ? ( ) : state === MetadataLoadState.Success ? (
Thumbnail
{metadata?.title}
{suggestions.length > 0 && ( <>

タグ候補
(クリックするとタグ入力欄にコピーできます)

    {suggestions.map((tag) => (
  • handleAddTag(tag.name)} > {tag.name}
  • ))}
)}
) : ( )}
); };