import styled from "@emotion/styled" import type { Attachment, AttachmentMetadata, Item } from "opvault.js" import { useEffect, useState } from "react" import { CategoryIcon } from "./CategoryIcon" import { ItemDates } from "./ItemDates" import { ItemFieldView, FieldContainer, FieldTitle, ItemDetailsFieldView, } from "./ItemField" import { ItemWarning } from "./ItemWarning" interface ItemViewProps { item: Item } const Header = styled.div` display: flex; align-items: center; ` const Icon = styled(CategoryIcon)` font-size: 2em; margin-right: 5px; ` const SectionTitle = styled.div` font-size: 85%; font-weight: 600; text-transform: uppercase; margin: 20px 0 10px; ` const Tag = styled.div` display: inline-block; margin-top: 2px; margin-right: 5px; border-radius: 4px; padding: 3px 7px; background-color: var(--label-background); ` const ExtraField = styled(FieldContainer)` margin-bottom: 20px; ` const ItemTitle = styled.h2`` const Container = styled.div` height: 100%; overflow: auto; padding: 0 10px; ` const Inner = styled.div` padding: 10px 0; ` const AttachmentContainer = styled.div` display: flex; margin: 5px 0; ` export const ItemView: React.FC = ({ item }) => (
{item.details.fields == null} {item.overview.title}
JSON
          {JSON.stringify({ overview: item.overview, details: item.details }, null, 2)}
        
{item.details.sections ?.filter(s => s.fields?.some(x => x.v != null)) .map((section, i) => (
{section.title != null && {section.title}} {section.fields?.map((field, j) => ( ))}
))}
{!!item.details.fields?.length && (
{item.details.fields!.map((field, i) => ( ))}
)} {item.details.notesPlain != null && ( notes

{item.details.notesPlain}

)} {!!item.overview.tags?.length && ( tags
{item.overview.tags!.map((tag, i) => ( {tag} ))}
)} {item.attachments.length > 0 && ( attachments
{item.attachments.map((file, i) => ( ))}
)}
) function AttachmentView({ file }: { file: Attachment }) { const [metadata, setMetadata] = useState() useEffect(() => { file.unlock().then(() => setMetadata(file.metadata)) }, [file]) if (!metadata) return null return {metadata.overview.filename} }