import { getTinyliciousContainer } from "@fluid-experimental/get-container" ; import { ContactCollectionContainerRuntimeFactory } from "./containerCode" ; import { IContact , IContactCollection } from "./dataObject" ; import { renderContact , renderContactCollection } from "./view" ; const searchParams = new URLSearchParams ( location . search ) ; const specifiedContact = searchParams . get ( "contact" ) ?? undefined ; param contactId returns const getContactUrl = ( contactId ) : string => { const contactUrl = new URL ( location . toString ( ) ) ; contactUrl . search = `?contact=${ contactId }` ; return contactUrl . toString ( ) ; } ; async function start ( ) { const shouldCreateNew = location . hash . length === 0 ; const documentId = ! shouldCreateNew ? window . location . hash . substring ( 1 ) : "" ; const [ container , containerId ] = await getTinyliciousContainer ( documentId , ContactCollectionContainerRuntimeFactory , shouldCreateNew ) ; location . hash = containerId ; document . title = containerId ; const url = `/${ specifiedContact ?? "" }` ; const response = await container . request ( { url } ) ; if ( response . status !== 200 || response . mimeType !== "fluid/object" ) { throw new Error ( `Unable to retrieve data object at URL: "${ url }"` ) ; } else if ( response . value === undefined ) { throw new Error ( `Empty response from URL: "${ url }"` ) ; } const div = document . getElementById ( "content" ) as HTMLDivElement ; if ( specifiedContact === undefined ) { const contactCollection = response . value ; renderContactCollection ( contactCollection , getContactUrl , div ) ; } else { const contact = response . value ; renderContact ( contact , div ) ; } } start ( ) . catch ( ( error ) => console . error ( error ) ) ;