Skip to content

Commit

Permalink
Merge pull request #300 from us3r-network/F-quickStartGuide-bufan
Browse files Browse the repository at this point in the history
F-quickStartGuide-bufan
  • Loading branch information
sin-bufan authored Feb 4, 2024
2 parents f67c115 + 29c68c9 commit 26dc58f
Show file tree
Hide file tree
Showing 21 changed files with 259 additions and 188 deletions.
70 changes: 35 additions & 35 deletions packages/client/dashboard/src/api/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,42 +212,42 @@ export function getModelSDK({
})
}

export function startIndexModel({
network,
modelId,
didSession,
}: {
network: Network
modelId: string
didSession?: string
}): AxiosPromise<ApiResp<null>> {
return axios({
url: `${APP_API_URL}/models/indexing?network=${network.toUpperCase()}&model=${modelId}`,
method: 'post',
headers: {
'did-session': didSession || '',
},
})
}
// export function startIndexModel({
// network,
// modelId,
// didSession,
// }: {
// network: Network
// modelId: string
// didSession?: string
// }): AxiosPromise<ApiResp<null>> {
// return axios({
// url: `${APP_API_URL}/models/indexing?network=${network.toUpperCase()}&model=${modelId}`,
// method: 'post',
// headers: {
// 'did-session': didSession || '',
// },
// })
// }

export function startIndexModels({
modelIds,
network,
didSession,
}:{
didSession: string,
modelIds: string[],
network: Network }) {
if (!modelIds || modelIds.length===0) return Promise.reject()
const resp = Promise.all(modelIds.map((modelId: string) => {
return startIndexModel({
modelId,
network,
didSession
})
}))
return resp
}
// export function startIndexModels({
// modelIds,
// network,
// didSession,
// }:{
// didSession: string,
// modelIds: string[],
// network: Network }) {
// if (!modelIds || modelIds.length===0) return Promise.reject()
// const resp = Promise.all(modelIds.map((modelId: string) => {
// return startIndexModel({
// modelId,
// network,
// didSession
// })
// }))
// return resp
// }

export function getStreamsCountWithModels({
network,
Expand Down
5 changes: 2 additions & 3 deletions packages/client/dashboard/src/components/common/ModalBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Heading,
Modal,
ModalOverlay,
ModalOverlayProps,
ModalOverlayProps
} from 'react-aria-components'
import styled, { keyframes } from 'styled-components'
import CloseIcon from '../icons/CloseIcon'
Expand All @@ -20,7 +20,7 @@ export interface ModalBaseProps extends ModalOverlayProps {
closeBtnClassName?: string
}

export default function ModalBase({
export default function ModalBase ({
children,
title,
showCloseBtn = true,
Expand All @@ -38,7 +38,6 @@ export default function ModalBase({
<DialogStyled className={dialogClassName}>
{(!!title || showCloseBtn) && (
<HeadingStyled className={headingClassName}>
{' '}
<span className={titleClassName}>{title}</span>
{showCloseBtn && (
<CloseBtnStyled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function DappSocialEditor({
<div key={item.platform} className="social-item">
<div>
{IconMap[item.platform] &&
React.createElement(IconMap[item.platform])}{' '}
React.createElement(IconMap[item.platform])}
<span>{item.platform}</span>
</div>
<a href={item.url} target="_blank" rel="noreferrer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const definition = ${JSON.stringify(runtimeDefinition)}`}
}

const Box = styled.div`
height: 100%;
.title {
display: flex;
align-items: center;
Expand All @@ -100,7 +101,7 @@ const Box = styled.div`
`

const EditorBox = styled.div`
max-height: 800px;
height: 100%;
background: #14171a;
border: 1px solid #39424c;
border-radius: 20px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ export default function CompositePublish ({
encodedDefinition: composite.composite,
createAt: new Date().toISOString()
}
console.log('compositeInput', compositeInput)
setPublishing(true)
const s3Composite = new S3CompositeModel(CERAMIC_TESTNET_HOST)
s3Composite.authComposeClient(session)
const stream = await s3Composite.createComposite({
content: compositeInput
})
console.log(stream)
const streamId = stream?.data?.createComposite?.document?.id
if (!streamId) {
toast.error('Publish failed')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { createDappComposites } from '../../api/composite'
import useSelectedDapp from '../../hooks/useSelectedDapp'
import { schemas } from '../../utils/composedb-types/schemas'
import CloseIcon from '../icons/CloseIcon'
import { createCompositeFromBrowser } from '../../utils/composeDBUtils'
import {
createCompositeFromBrowser,
startIndexModelsFromBrowser
} from '../../utils/composeDBUtils'
import { useCeramicNodeCtx } from '../../context/CeramicNodeCtx'
import { startIndexModels } from '../../api/model'

export default function CreateNewComposite ({
closeModal,
Expand Down Expand Up @@ -44,18 +46,17 @@ export default function CreateNewComposite ({
const result = await createCompositeFromBrowser(
gqlSchema.code,
currCeramicNode.serviceUrl + '/',
// `http://${ceramicNodes[0].serviceK8sMetadata.ceramicLoadbalanceHost}:${ceramicNodes[0].serviceK8sMetadata.ceramicLoadbalancePort}`,
currCeramicNode.privateKey,
session
)
if (!result) return
const { composite, runtimeDefinition } = result

const newCompositeData = {
graphql: gqlSchema.code,
name,
composite:JSON.stringify(composite),
runtimeDefinition:JSON.stringify(runtimeDefinition),
composite: JSON.stringify(composite),
runtimeDefinition: JSON.stringify(runtimeDefinition)
}
const resp = await createDappComposites({
data: newCompositeData,
Expand All @@ -66,11 +67,12 @@ export default function CreateNewComposite ({
throw new Error(resp.data.msg)
}
const modelIds = composite.modelIDs
await startIndexModels({
await startIndexModelsFromBrowser(
modelIds,
network: selectedDapp.network,
didSession: session.serialize()
}).catch(console.error)
selectedDapp.network,
currCeramicNode.serviceUrl + '/',
currCeramicNode.privateKey
)

if (loadDappComposites) await loadDappComposites()
closeModal()
Expand Down Expand Up @@ -100,7 +102,7 @@ export default function CreateNewComposite ({
</button>
</div>
<div className='name'>
<span>Composite Name:</span>{' '}
<span>Composite Name:</span>
<input
type='text'
placeholder='Enter composite name'
Expand Down
34 changes: 11 additions & 23 deletions packages/client/dashboard/src/components/model/CreateNewModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ import { AxiosError } from 'axios'
import { GraphQLEditor, PassedSchema } from 'graphql-editor'
import { useCallback, useState } from 'react'
import styled from 'styled-components'
import { updateDapp } from '../../api/dapp'
import { useAppCtx } from '../../context/AppCtx'
import { createDappModels } from '../../api/model'
import { useCeramicNodeCtx } from '../../context/CeramicNodeCtx'
import useSelectedDapp from '../../hooks/useSelectedDapp'
import { schemas } from '../../utils/composedb-types/schemas'
import { createCompositeFromBrowser } from '../../utils/composeDBUtils'
import { schemas } from '../../utils/composedb-types/schemas'
import CloseIcon from '../icons/CloseIcon'
import { createDappModels } from '../../api/model'

export default function CreateNewModel ({
loadDappModels,
closeModal
}: {
loadDappModels?: () => Promise<void>
closeModal: () => void
}) {
const { selectedDapp } = useSelectedDapp()
const { currCeramicNode } = useCeramicNodeCtx()
const { loadDapps } = useAppCtx()
const session = useSession()
const [submitting, setSubmitting] = useState(false)

Expand All @@ -45,27 +44,20 @@ export default function CreateNewModel ({
// const { composite, runtimeDefinition } = resp.data.data
// const newModelIDs = Object.key(composite.models)

// create model directly through the ceramic node
// create model directly through the ceramic node and index it
const result = await createCompositeFromBrowser(
gqlSchema.code,
currCeramicNode.serviceUrl + '/',
// `http://${ceramicNodes[0].serviceK8sMetadata.ceramicLoadbalanceHost}:${ceramicNodes[0].serviceK8sMetadata.ceramicLoadbalancePort}`,
currCeramicNode.privateKey,
session
session,
true, // start index model on my private node
)
if (!result) return
const { composite, runtimeDefinition } = result
const newModelIDs = Object.values(composite.modelIDs)
// const models = selectedDapp.models || []
// models.push(...newModelIDs)
// // console.log("models: ", newModelIDs, models)
// await updateDapp(
// { ...selectedDapp, models },
// session.serialize(),
// currCeramicNode.id
// )
// await loadDapps()
const resp = await Promise.all(
//save new model to dapp
await Promise.all(
newModelIDs.map(async mdoelStreamId => {
return await createDappModels({
data: { mdoelStreamId, gqlSchema, composite, runtimeDefinition },
Expand All @@ -74,16 +66,15 @@ export default function CreateNewModel ({
})
})
)
console.log(resp)
await loadDappModels()
loadDappModels?.()
closeModal()
} catch (error) {
const err = error as AxiosError
console.error(err)
} finally {
setSubmitting(false)
}
}, [submitting, selectedDapp, session, gqlSchema, currCeramicNode, closeModal])
}, [submitting, selectedDapp, session, gqlSchema, currCeramicNode, loadDappModels, closeModal])

return (
<CreateBox>
Expand Down Expand Up @@ -192,6 +183,3 @@ const CreateBox = styled.div`
}
}
`
function loadDappModels () {
throw new Error('Function not implemented.')
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useLocation } from 'react-router-dom'
import styled from 'styled-components'
import { deleteDappComposites, getDappComposites } from '../../api/composite'
import { updateDapp } from '../../api/dapp'
import { getModelsInfoByIds } from '../../api/model'
import { getDappModels, getModelsInfoByIds } from '../../api/model'
import { useAppCtx } from '../../context/AppCtx'
import { useCeramicNodeCtx } from '../../context/CeramicNodeCtx'
import useIsOwner from '../../hooks/useIsOwner'
Expand Down Expand Up @@ -65,7 +65,7 @@ export default function DappModelAndComposites ({
editable?: boolean
}) {
const session = useSession()
const { loadDapps, currDapp } = useAppCtx()
const { loadDapps, currDapp, loadCurrDapp } = useAppCtx()
const { appId, selectedDapp } = useSelectedDapp()
const { currCeramicNode } = useCeramicNodeCtx()
const [loading, setLoading] = useState(false)
Expand Down Expand Up @@ -102,18 +102,19 @@ export default function DappModelAndComposites ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dapp])

// const loadDappModels = useCallback(async () => {
// if (!dapp) return
// try {
// const resp = await getDappModels({
// dapp
// })
// if (resp.data.code !== 0) throw new Error(resp.data.msg)
// setDappModels(resp.data.data)
// } catch (error) {
// console.error(error)
// }
// }, [dapp])
const loadDappModels = useCallback(async () => {
if (!dapp) return
// try {
// const resp = await getDappModels({
// dapp
// })
// if (resp.data.code !== 0) throw new Error(resp.data.msg)
// setDappModels(resp.data.data)
// } catch (error) {
// console.error(error)
// }
await loadCurrDapp()
}, [dapp, loadCurrDapp])

const loadDappComposites = useCallback(async () => {
if (!dapp) return
Expand Down Expand Up @@ -342,7 +343,8 @@ export default function DappModelAndComposites ({
isOpen={openModal === OPEN_MODAL.CREATE_NEW_MODEL}
onOpenChange={() => setOpenModal(OPEN_MODAL.NONE)}
>
<Dialog>{({ close }) => <CreateNewModel closeModal={close} />}</Dialog>
<Dialog>{({ close }) => <CreateNewModel closeModal={close}
loadDappModels={loadDappModels}/>}</Dialog>
</Modal>
{/* CREATE_NEW_COMPOSITE modal */}
<Modal
Expand Down Expand Up @@ -574,7 +576,7 @@ function RemoveButton ({
if (removing) {
return (
<div className='removing'>
<img src='/loading.gif' title='loading' alt='' />{' '}
<img src='/loading.gif' title='loading' alt='' />
</div>
)
}
Expand Down
Loading

0 comments on commit 26dc58f

Please sign in to comment.