From b1f506e287a7281f6641bb0e4d858759e13b6a53 Mon Sep 17 00:00:00 2001 From: bufan Date: Fri, 2 Feb 2024 10:44:13 +0800 Subject: [PATCH 1/6] remove extra code --- .../client/dashboard/src/components/common/ModalBase.tsx | 5 ++--- .../dashboard/src/components/dapp/DappSocialEditor.tsx | 2 +- .../dashboard/src/components/model/CreateNewComposite.tsx | 2 +- .../src/components/model/DappModelAndComposites.tsx | 2 +- .../dashboard/src/components/model/ExploreCompositeList.tsx | 5 ++--- packages/client/dashboard/src/container/DappQuickStart.tsx | 3 +-- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/client/dashboard/src/components/common/ModalBase.tsx b/packages/client/dashboard/src/components/common/ModalBase.tsx index d8e7583..be27672 100644 --- a/packages/client/dashboard/src/components/common/ModalBase.tsx +++ b/packages/client/dashboard/src/components/common/ModalBase.tsx @@ -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' @@ -20,7 +20,7 @@ export interface ModalBaseProps extends ModalOverlayProps { closeBtnClassName?: string } -export default function ModalBase({ +export default function ModalBase ({ children, title, showCloseBtn = true, @@ -38,7 +38,6 @@ export default function ModalBase({ {(!!title || showCloseBtn) && ( - {' '} {title} {showCloseBtn && (
{IconMap[item.platform] && - React.createElement(IconMap[item.platform])}{' '} + React.createElement(IconMap[item.platform])} {item.platform}
diff --git a/packages/client/dashboard/src/components/model/CreateNewComposite.tsx b/packages/client/dashboard/src/components/model/CreateNewComposite.tsx index d739c97..49fcdd7 100644 --- a/packages/client/dashboard/src/components/model/CreateNewComposite.tsx +++ b/packages/client/dashboard/src/components/model/CreateNewComposite.tsx @@ -100,7 +100,7 @@ export default function CreateNewComposite ({
- Composite Name:{' '} + Composite Name: - {' '} +
) } diff --git a/packages/client/dashboard/src/components/model/ExploreCompositeList.tsx b/packages/client/dashboard/src/components/model/ExploreCompositeList.tsx index 367a3d7..62043bc 100644 --- a/packages/client/dashboard/src/components/model/ExploreCompositeList.tsx +++ b/packages/client/dashboard/src/components/model/ExploreCompositeList.tsx @@ -216,11 +216,10 @@ function Actions ({ } }, [session, selectedDapp, ceramicNodeId, hasIndexed, composite, loadDapps]) return ( - + diff --git a/packages/client/dashboard/src/container/DappQuickStart.tsx b/packages/client/dashboard/src/container/DappQuickStart.tsx index 467e8e0..edace87 100644 --- a/packages/client/dashboard/src/container/DappQuickStart.tsx +++ b/packages/client/dashboard/src/container/DappQuickStart.tsx @@ -145,7 +145,7 @@ const DeployNode = () => { {' '} + />

You must create a Ceramic node, as all data operations will be executed on this node. @@ -172,7 +172,6 @@ const StartBuilding = () => { if (firstModel) { return ( <> - {' '} Date: Fri, 2 Feb 2024 12:06:39 +0800 Subject: [PATCH 2/6] remove extra log --- .../src/components/model/CompositePublish.tsx | 2 -- .../src/components/model/CreateNewModel.tsx | 2 -- .../components/model/ExploreCompositeList.tsx | 2 -- .../src/components/model/ExploreModelList.tsx | 24 +++++++++++++---- .../src/components/model/ModelSDK.tsx | 1 - .../dashboard/src/components/nav/Header.tsx | 12 ++++----- .../node/DeleteCeramicNodeModal.tsx | 1 - .../src/components/node/NodeStatus.tsx | 4 +-- .../src/container/DappPlayground.tsx | 1 - .../dashboard/src/container/MyDapps.tsx | 1 - .../dashboard/src/hooks/useSelectedDapp.ts | 26 +++---------------- .../dashboard/src/utils/composeDBUtils.ts | 2 +- 12 files changed, 31 insertions(+), 47 deletions(-) diff --git a/packages/client/dashboard/src/components/model/CompositePublish.tsx b/packages/client/dashboard/src/components/model/CompositePublish.tsx index 7c246e0..1d738dd 100644 --- a/packages/client/dashboard/src/components/model/CompositePublish.tsx +++ b/packages/client/dashboard/src/components/model/CompositePublish.tsx @@ -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') diff --git a/packages/client/dashboard/src/components/model/CreateNewModel.tsx b/packages/client/dashboard/src/components/model/CreateNewModel.tsx index 0a534fa..765bea3 100644 --- a/packages/client/dashboard/src/components/model/CreateNewModel.tsx +++ b/packages/client/dashboard/src/components/model/CreateNewModel.tsx @@ -58,7 +58,6 @@ export default function CreateNewModel ({ const newModelIDs = Object.values(composite.modelIDs) // const models = selectedDapp.models || [] // models.push(...newModelIDs) - // // console.log("models: ", newModelIDs, models) // await updateDapp( // { ...selectedDapp, models }, // session.serialize(), @@ -74,7 +73,6 @@ export default function CreateNewModel ({ }) }) ) - console.log(resp) await loadDappModels() closeModal() } catch (error) { diff --git a/packages/client/dashboard/src/components/model/ExploreCompositeList.tsx b/packages/client/dashboard/src/components/model/ExploreCompositeList.tsx index 62043bc..e67a3cc 100644 --- a/packages/client/dashboard/src/components/model/ExploreCompositeList.tsx +++ b/packages/client/dashboard/src/components/model/ExploreCompositeList.tsx @@ -76,7 +76,6 @@ export function CompositeList ({ next={() => { pageNum.current += 1 fetchMoreComposites(pageNum.current) - console.log('fetch more') }} hasMore={hasMore} loader={Loading...} @@ -185,7 +184,6 @@ function Actions ({ .then( () => { const models = JSON.parse(composite.composite).models - console.log(Object.keys(models)) const modelIds = Object.keys(models) startIndexModels({ modelIds, diff --git a/packages/client/dashboard/src/components/model/ExploreModelList.tsx b/packages/client/dashboard/src/components/model/ExploreModelList.tsx index cb72a24..861923c 100644 --- a/packages/client/dashboard/src/components/model/ExploreModelList.tsx +++ b/packages/client/dashboard/src/components/model/ExploreModelList.tsx @@ -11,7 +11,7 @@ import { import InfiniteScroll from 'react-infinite-scroll-component' import styled from 'styled-components' import { updateDapp } from '../../api/dapp' -import { PAGE_SIZE } from '../../constants' +import { CERAMIC_MAINNET_HOST, CERAMIC_TESTNET_HOST, PAGE_SIZE } from '../../constants' import { getModelStreamList, getModelsInfoByIds, @@ -30,6 +30,7 @@ import { useCeramicNodeCtx } from '../../context/CeramicNodeCtx' import useSelectedDapp from '../../hooks/useSelectedDapp' import { CeramicStatus, ClientDApp, ModelStream, Network } from '../../types.d' import { shortPubKey } from '../../utils/shortPubKey' +import { S3ModelCollectionModel } from '@us3r-network/data-model' export default function ModelList ({ searchText, @@ -39,7 +40,7 @@ export default function ModelList ({ filterStar?: boolean }) { // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { s3ModelCollection, selectedDapp } = useSelectedDapp() + const { selectedDapp } = useSelectedDapp() const { currCeramicNode } = useCeramicNodeCtx() const session = useSession() const [models, setModels] = useState>([]) @@ -49,9 +50,16 @@ export default function ModelList ({ const [personalCollections, setPersonalCollections] = useState< PersonalCollection[] >([]) + + const s3ModelCollection = useMemo(() => { + if (selectedDapp?.network === Network.MAINNET) { + return new S3ModelCollectionModel(CERAMIC_MAINNET_HOST, 'mainnet') + } + return new S3ModelCollectionModel(CERAMIC_TESTNET_HOST, 'testnet') + }, [selectedDapp?.network]) + const fetchPersonalCollections = useCallback(async () => { if (!session) return - s3ModelCollection.authComposeClient(session) try { const personal = await s3ModelCollection.queryPersonalCollections({ first: 500 @@ -155,7 +163,6 @@ export default function ModelList ({ next={() => { pageNum.current += 1 fetchMoreModel(pageNum.current) - console.log('fetch more') }} hasMore={filterStar ? false : hasMore} loader={Loading...} @@ -376,12 +383,19 @@ function Actions ({ ceramicNodeId?: number }) { const session = useSession() - const { s3ModelCollection } = useSelectedDapp() const [staring, setStaring] = useState(false) const { loadDapps, loadCurrDapp } = useAppCtx() const { selectedDapp } = useSelectedDapp() const [adding, setAdding] = useState(false) + + const s3ModelCollection = useMemo(() => { + if (selectedDapp?.network === Network.MAINNET) { + return new S3ModelCollectionModel(CERAMIC_MAINNET_HOST, 'mainnet') + } + return new S3ModelCollectionModel(CERAMIC_TESTNET_HOST, 'testnet') + }, [selectedDapp?.network]) + const addModelToDapp = useCallback( async (modelId: string) => { if (!session || !selectedDapp) return diff --git a/packages/client/dashboard/src/components/model/ModelSDK.tsx b/packages/client/dashboard/src/components/model/ModelSDK.tsx index 8e1b91e..d5e9441 100644 --- a/packages/client/dashboard/src/components/model/ModelSDK.tsx +++ b/packages/client/dashboard/src/components/model/ModelSDK.tsx @@ -162,7 +162,6 @@ export const definition = ${JSON.stringify( {codes.map(item => { - console.log('item', item) return ( diff --git a/packages/client/dashboard/src/components/nav/Header.tsx b/packages/client/dashboard/src/components/nav/Header.tsx index c851047..9fc1f4e 100644 --- a/packages/client/dashboard/src/components/nav/Header.tsx +++ b/packages/client/dashboard/src/components/nav/Header.tsx @@ -3,17 +3,17 @@ import { useMemo } from 'react' import { Link, useLocation, useNavigate } from 'react-router-dom' import { Item } from 'react-stately' import styled from 'styled-components' -import useSelectedDapp from '../../hooks/useSelectedDapp' import { Label } from '../common/ListBox' import { Select } from '../common/Select' import LoginButton from './LoginButton' import { LogoWhite } from './Logo' +import { useAppCtx } from '../../context/AppCtx' +import { ClientDApp } from '../../types' export default function Header() { - const { appId, selectDapps } = useSelectedDapp() const session = useSession() - + const { dapps, currAppId } = useAppCtx() return (

@@ -21,8 +21,8 @@ export default function Header() {

CONSOLE

- {session?.id && appId && ( - + {session?.id && currAppId && ( + )}
@@ -82,7 +82,7 @@ function DappSelector({ dapps, selected, }: { - dapps: { id: number; name: string }[] + dapps: ClientDApp[] selected: string }) { const navigate = useNavigate() diff --git a/packages/client/dashboard/src/components/node/DeleteCeramicNodeModal.tsx b/packages/client/dashboard/src/components/node/DeleteCeramicNodeModal.tsx index 59611b9..e3743e7 100644 --- a/packages/client/dashboard/src/components/node/DeleteCeramicNodeModal.tsx +++ b/packages/client/dashboard/src/components/node/DeleteCeramicNodeModal.tsx @@ -31,7 +31,6 @@ export default function DeleteCeramicNodeModal ({ return } if (nodeName.trim() !== node.name.trim()) { - console.log('Node Name: ', nodeName, node.name) alert('Node name is not correct!') return } diff --git a/packages/client/dashboard/src/components/node/NodeStatus.tsx b/packages/client/dashboard/src/components/node/NodeStatus.tsx index 18309b7..c93d31a 100644 --- a/packages/client/dashboard/src/components/node/NodeStatus.tsx +++ b/packages/client/dashboard/src/components/node/NodeStatus.tsx @@ -17,7 +17,7 @@ export default function NodeStatus ({ useEffect(() => { if (status !== CeramicStatus.PREPARING) return if (prepageingPercentage < 100) { - console.log('set prepare timeout', prepageingPercentage) + // console.log('set prepare timeout', prepageingPercentage) setTimeout(() => { setPrepageingPercentage(prepageingPercentage + 1) }, 350) @@ -27,7 +27,7 @@ export default function NodeStatus ({ useEffect(() => { if (status !== CeramicStatus.STARTING) return if (startingPercentage < 100) { - console.log('set start timeout', startingPercentage) + // console.log('set start timeout', startingPercentage) setTimeout(() => { setStartingPercentage(startingPercentage + 1) }, 200) diff --git a/packages/client/dashboard/src/container/DappPlayground.tsx b/packages/client/dashboard/src/container/DappPlayground.tsx index 64c083e..c8eba2f 100644 --- a/packages/client/dashboard/src/container/DappPlayground.tsx +++ b/packages/client/dashboard/src/container/DappPlayground.tsx @@ -77,7 +77,6 @@ function ModelPlayground ({ streamId, network || Network.TESTNET ) - console.log('data', resp) setModelData(resp.data.data) } catch (error) { const err = error as AxiosError diff --git a/packages/client/dashboard/src/container/MyDapps.tsx b/packages/client/dashboard/src/container/MyDapps.tsx index 9f8cd10..56e1ed3 100644 --- a/packages/client/dashboard/src/container/MyDapps.tsx +++ b/packages/client/dashboard/src/container/MyDapps.tsx @@ -14,7 +14,6 @@ import { useEffect } from 'react' export default function MyDapps() { const { dapps, setCurrAppId } = useAppCtx() - setCurrAppId('') useEffect(() => { setCurrAppId('') }, [setCurrAppId]) diff --git a/packages/client/dashboard/src/hooks/useSelectedDapp.ts b/packages/client/dashboard/src/hooks/useSelectedDapp.ts index 338033d..4cfebdd 100644 --- a/packages/client/dashboard/src/hooks/useSelectedDapp.ts +++ b/packages/client/dashboard/src/hooks/useSelectedDapp.ts @@ -1,38 +1,18 @@ -import { S3ModelCollectionModel } from '@us3r-network/data-model' import { useMemo } from 'react' import { useParams } from 'react-router-dom' -import { CERAMIC_MAINNET_HOST, CERAMIC_TESTNET_HOST } from '../constants' import { useAppCtx } from '../context/AppCtx' -import { Network } from '../types.d' +// todo: this hook is NOT simimalr to useAppCtx, can be removed later export default function useSelectedDapp() { const { dapps, currAppId } = useAppCtx() const { appId } = useParams() - const selectDapps = useMemo(() => { - return ( - dapps?.map((item) => ({ - ...item, - id: item.id!, - name: item.name, - })) || [] - ) - }, [dapps]) const selectedDapp = useMemo(() => { - return selectDapps?.find((item) => item.id === Number(currAppId || appId)) - }, [selectDapps, currAppId, appId]) - - const s3ModelCollection = useMemo(() => { - if (selectedDapp?.network === Network.MAINNET) { - return new S3ModelCollectionModel(CERAMIC_MAINNET_HOST, 'mainnet') - } - return new S3ModelCollectionModel(CERAMIC_TESTNET_HOST, 'testnet') - }, [selectedDapp?.network]) + return dapps?.find((item) => item.id === Number(currAppId || appId)) + }, [dapps, currAppId, appId]) return { appId, selectedDapp, - selectDapps, - s3ModelCollection, } } diff --git a/packages/client/dashboard/src/utils/composeDBUtils.ts b/packages/client/dashboard/src/utils/composeDBUtils.ts index 29b49e2..43be39e 100644 --- a/packages/client/dashboard/src/utils/composeDBUtils.ts +++ b/packages/client/dashboard/src/utils/composeDBUtils.ts @@ -130,7 +130,7 @@ export async function getRuntimeDefinitionFromEncodedComposite( // console.log('runtime definition:', composite.toRuntime()) return composite.toRuntime() } catch (error) { - console.log('get runtime error', error) + console.error('get runtime error', error) return null } } \ No newline at end of file From 8c36afcdbc750f65e0001e90b476ef8ac67db200 Mon Sep 17 00:00:00 2001 From: bufan Date: Fri, 2 Feb 2024 13:02:25 +0800 Subject: [PATCH 3/6] remove extra log --- .../src/components/model/ExploreModelList.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/client/dashboard/src/components/model/ExploreModelList.tsx b/packages/client/dashboard/src/components/model/ExploreModelList.tsx index 861923c..1ccae8f 100644 --- a/packages/client/dashboard/src/components/model/ExploreModelList.tsx +++ b/packages/client/dashboard/src/components/model/ExploreModelList.tsx @@ -56,16 +56,17 @@ export default function ModelList ({ return new S3ModelCollectionModel(CERAMIC_MAINNET_HOST, 'mainnet') } return new S3ModelCollectionModel(CERAMIC_TESTNET_HOST, 'testnet') - }, [selectedDapp?.network]) + }, [selectedDapp]) const fetchPersonalCollections = useCallback(async () => { - if (!session) return + if (!session || !s3ModelCollection) return try { + s3ModelCollection.authComposeClient(session) const personal = await s3ModelCollection.queryPersonalCollections({ first: 500 }) if (personal.errors) throw new Error(personal.errors[0].message) - const collected = personal.data?.viewer.modelCollectionList + const collected = personal.data?.viewer?.modelCollectionList if (collected) { setPersonalCollections( @@ -141,8 +142,11 @@ export default function ModelList ({ useEffect(() => { fetchModel() + }, [fetchModel]) + + useEffect(() => { fetchPersonalCollections() - }, [fetchModel, fetchPersonalCollections]) + }, [fetchPersonalCollections]) useEffect(() => { fetchStarModels().catch(err => { From 12ee18ad23851d04e14f88b425dcf2b4d6dca13a Mon Sep 17 00:00:00 2001 From: bufan Date: Fri, 2 Feb 2024 13:14:57 +0800 Subject: [PATCH 4/6] fix editor style --- .../dashboard/src/components/model/CompositeEditor.tsx | 3 ++- packages/client/dashboard/src/container/DappEditor.tsx | 10 ++++++---- .../client/dashboard/src/container/DappPlayground.tsx | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/client/dashboard/src/components/model/CompositeEditor.tsx b/packages/client/dashboard/src/components/model/CompositeEditor.tsx index aaa0ccf..2438708 100644 --- a/packages/client/dashboard/src/components/model/CompositeEditor.tsx +++ b/packages/client/dashboard/src/components/model/CompositeEditor.tsx @@ -77,6 +77,7 @@ export const definition = ${JSON.stringify(runtimeDefinition)}`} } const Box = styled.div` + height: 100%; .title { display: flex; align-items: center; @@ -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; diff --git a/packages/client/dashboard/src/container/DappEditor.tsx b/packages/client/dashboard/src/container/DappEditor.tsx index 6dfff74..46cf89c 100644 --- a/packages/client/dashboard/src/container/DappEditor.tsx +++ b/packages/client/dashboard/src/container/DappEditor.tsx @@ -27,10 +27,12 @@ export default function DappEditor () {
{selectModel.stream_content?.name}
- +
+ +
) } diff --git a/packages/client/dashboard/src/container/DappPlayground.tsx b/packages/client/dashboard/src/container/DappPlayground.tsx index c8eba2f..aac2ba3 100644 --- a/packages/client/dashboard/src/container/DappPlayground.tsx +++ b/packages/client/dashboard/src/container/DappPlayground.tsx @@ -27,7 +27,7 @@ export default function DappPlayground () {
{selectModel.stream_content.name}
-
+
{selectComposite.name}
-
+
Date: Fri, 2 Feb 2024 17:25:36 +0800 Subject: [PATCH 5/6] start index from browser --- .../components/model/CreateNewComposite.tsx | 22 ++--- .../src/components/model/CreateNewModel.tsx | 32 +++---- .../model/DappModelAndComposites.tsx | 32 +++---- .../components/model/ExploreCompositeList.tsx | 18 ++-- .../src/components/model/ExploreModelList.tsx | 45 +++++----- .../src/components/model/ModelSDK.tsx | 2 +- .../dashboard/src/container/DappEditor.tsx | 4 +- .../dashboard/src/utils/composeDBUtils.ts | 90 +++++++++++++++++++ 8 files changed, 164 insertions(+), 81 deletions(-) diff --git a/packages/client/dashboard/src/components/model/CreateNewComposite.tsx b/packages/client/dashboard/src/components/model/CreateNewComposite.tsx index 49fcdd7..377f36a 100644 --- a/packages/client/dashboard/src/components/model/CreateNewComposite.tsx +++ b/packages/client/dashboard/src/components/model/CreateNewComposite.tsx @@ -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, @@ -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, @@ -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() diff --git a/packages/client/dashboard/src/components/model/CreateNewModel.tsx b/packages/client/dashboard/src/components/model/CreateNewModel.tsx index 765bea3..5928ff7 100644 --- a/packages/client/dashboard/src/components/model/CreateNewModel.tsx +++ b/packages/client/dashboard/src/components/model/CreateNewModel.tsx @@ -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 closeModal: () => void }) { const { selectedDapp } = useSelectedDapp() const { currCeramicNode } = useCeramicNodeCtx() - const { loadDapps } = useAppCtx() const session = useSession() const [submitting, setSubmitting] = useState(false) @@ -45,26 +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) - // 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 }, @@ -73,7 +66,7 @@ export default function CreateNewModel ({ }) }) ) - await loadDappModels() + loadDappModels?.() closeModal() } catch (error) { const err = error as AxiosError @@ -81,7 +74,7 @@ export default function CreateNewModel ({ } finally { setSubmitting(false) } - }, [submitting, selectedDapp, session, gqlSchema, currCeramicNode, closeModal]) + }, [submitting, selectedDapp, session, gqlSchema, currCeramicNode, loadDappModels, closeModal]) return ( @@ -190,6 +183,3 @@ const CreateBox = styled.div` } } ` -function loadDappModels () { - throw new Error('Function not implemented.') -} diff --git a/packages/client/dashboard/src/components/model/DappModelAndComposites.tsx b/packages/client/dashboard/src/components/model/DappModelAndComposites.tsx index b0fd0a0..2c8d5a1 100644 --- a/packages/client/dashboard/src/components/model/DappModelAndComposites.tsx +++ b/packages/client/dashboard/src/components/model/DappModelAndComposites.tsx @@ -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' @@ -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) @@ -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 @@ -342,7 +343,8 @@ export default function DappModelAndComposites ({ isOpen={openModal === OPEN_MODAL.CREATE_NEW_MODEL} onOpenChange={() => setOpenModal(OPEN_MODAL.NONE)} > - {({ close }) => } + {({ close }) => } {/* CREATE_NEW_COMPOSITE modal */} { if (!session || !selectedDapp) return - if (!ceramicNodeId) return + if (!currCeramicNode) return if (!hasIndexed) { bindingDappComposites({ compositeId: composite.id, @@ -185,11 +185,12 @@ function Actions ({ () => { const models = JSON.parse(composite.composite).models const modelIds = Object.keys(models) - startIndexModels({ + startIndexModelsFromBrowser( modelIds, - network: selectedDapp.network, - didSession: session.serialize() - }).catch(console.error) + selectedDapp.network, + currCeramicNode.serviceUrl + '/', + currCeramicNode.privateKey + ) }, err => { console.error(err) @@ -204,7 +205,6 @@ function Actions ({ await updateDapp( { ...selectedDapp, composites }, session.serialize(), - ceramicNodeId ) await loadDapps() } catch (err) { @@ -212,7 +212,7 @@ function Actions ({ } finally { setAdding(false) } - }, [session, selectedDapp, ceramicNodeId, hasIndexed, composite, loadDapps]) + }, [session, selectedDapp, currCeramicNode, hasIndexed, composite, loadDapps]) return ( diff --git a/packages/client/dashboard/src/components/model/ExploreModelList.tsx b/packages/client/dashboard/src/components/model/ExploreModelList.tsx index 1ccae8f..8aa2fe7 100644 --- a/packages/client/dashboard/src/components/model/ExploreModelList.tsx +++ b/packages/client/dashboard/src/components/model/ExploreModelList.tsx @@ -15,7 +15,6 @@ import { CERAMIC_MAINNET_HOST, CERAMIC_TESTNET_HOST, PAGE_SIZE } from '../../con import { getModelStreamList, getModelsInfoByIds, - startIndexModel } from '../../api/model' import { ImgOrName } from '../common/ImgOrName' import { TableBox, TableContainer } from '../common/TableBox' @@ -28,9 +27,10 @@ import { S3_SCAN_URL } from '../../constants' import { PersonalCollection, useAppCtx } from '../../context/AppCtx' import { useCeramicNodeCtx } from '../../context/CeramicNodeCtx' import useSelectedDapp from '../../hooks/useSelectedDapp' -import { CeramicStatus, ClientDApp, ModelStream, Network } from '../../types.d' +import { ClientDApp, ModelStream, Network } from '../../types.d' import { shortPubKey } from '../../utils/shortPubKey' import { S3ModelCollectionModel } from '@us3r-network/data-model' +import { startIndexModelsFromBrowser } from '../../utils/composeDBUtils' export default function ModelList ({ searchText, @@ -41,7 +41,6 @@ export default function ModelList ({ }) { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { selectedDapp } = useSelectedDapp() - const { currCeramicNode } = useCeramicNodeCtx() const session = useSession() const [models, setModels] = useState>([]) const [starModels, setStarModels] = useState>([]) @@ -264,15 +263,9 @@ export default function ModelList ({ {/* */} @@ -372,7 +365,6 @@ function Actions ({ fetchPersonal, stream_id, hasIndexed, - ceramicNodeId }: { hasIndexed: boolean stream_id: string @@ -384,9 +376,9 @@ function Actions ({ } | undefined fetchPersonal: () => void - ceramicNodeId?: number }) { const session = useSession() + const { currCeramicNode } = useCeramicNodeCtx() const [staring, setStaring] = useState(false) const { loadDapps, loadCurrDapp } = useAppCtx() @@ -403,13 +395,20 @@ function Actions ({ const addModelToDapp = useCallback( async (modelId: string) => { if (!session || !selectedDapp) return - if (!ceramicNodeId) return + if (!currCeramicNode) return + console.log('currCeramicNode', currCeramicNode, hasIndexed) if (!hasIndexed) { - startIndexModel({ - modelId, - network: selectedDapp.network as Network, - didSession: session.serialize() - }).catch(console.error) + // await startIndexModel({ + // modelId, + // network: selectedDapp.network as Network, + // didSession: session.serialize() + // }).catch(console.error) + await startIndexModelsFromBrowser( + [modelId], + selectedDapp.network as Network, + currCeramicNode.serviceUrl + '/', + currCeramicNode.privateKey, + ) } try { setAdding(true) @@ -418,7 +417,7 @@ function Actions ({ await updateDapp( { ...selectedDapp, models }, session.serialize(), - ceramicNodeId + // ceramicNodeId ) await loadDapps() await loadCurrDapp() @@ -428,7 +427,7 @@ function Actions ({ setAdding(false) } }, - [session, selectedDapp, ceramicNodeId, hasIndexed, loadDapps, loadCurrDapp] + [session, selectedDapp, hasIndexed, loadDapps, loadCurrDapp,currCeramicNode] ) const collectModel = useCallback( @@ -500,11 +499,11 @@ function Actions ({ - ) : ceramicNodeId ? ( + ) : currCeramicNode ? (