diff --git a/packages/client/scan/package.json b/packages/client/scan/package.json index ee41473d..77548d92 100644 --- a/packages/client/scan/package.json +++ b/packages/client/scan/package.json @@ -35,7 +35,7 @@ "lodash-es": "^4.17.21", "monaco-editor": "^0.36.1", "react": "^18.2.0", - "react-aria-components": "^1.0.0-alpha.3", + "react-aria-components": "^1.0.0-alpha.5", "react-device-detect": "^2.2.2", "react-dom": "^18.2.0", "react-ga4": "^2.0.0", diff --git a/packages/client/scan/src/api/index.ts b/packages/client/scan/src/api/index.ts index 081721c2..9c0c8133 100644 --- a/packages/client/scan/src/api/index.ts +++ b/packages/client/scan/src/api/index.ts @@ -211,3 +211,21 @@ export function uploadImage({ file }: { file: File }) { data: form, }) } + +export function startIndexModel({ + network, + modelId, + didSession, +}: { + network: Network + modelId: string + didSession?: string +}): AxiosPromise> { + return axios({ + url: `${API_BASE_URL}/models/indexing?network=${network.toUpperCase()}&model=${modelId}`, + method: 'post', + headers: { + 'did-session': didSession || '', + }, + }) +} diff --git a/packages/client/scan/src/components/Dapp/Tabs.tsx b/packages/client/scan/src/components/Dapp/Tabs.tsx index 28fb9450..4859232b 100644 --- a/packages/client/scan/src/components/Dapp/Tabs.tsx +++ b/packages/client/scan/src/components/Dapp/Tabs.tsx @@ -1,4 +1,4 @@ -import { Tabs, TabList, Tab, TabPanels, TabPanel } from 'react-aria-components' +import { Tabs, TabList, Tab, TabPanel } from 'react-aria-components' import Definition from './Definition' import Instance from './Instance' import PlaygroundGraphiQL from './Playground' @@ -20,17 +20,16 @@ export default function ModelTabs({ Model Playground - - - - - - - - - - - + + + + + + + + + + ) } diff --git a/packages/client/scan/src/container/ModelView.tsx b/packages/client/scan/src/container/ModelView.tsx index 8f5c4029..be5b1b8b 100644 --- a/packages/client/scan/src/container/ModelView.tsx +++ b/packages/client/scan/src/container/ModelView.tsx @@ -1,24 +1,17 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { useParams } from 'react-router-dom' -import { Tabs, TabList, Tab, TabPanels, TabPanel } from 'react-aria-components' -import { getModelInfo } from '../api' +import { Tabs, TabList, Tab, TabPanel } from 'react-aria-components' +import { getModelInfo, startIndexModel } from '../api' import { ModelStream } from '../types' import { useCeramicCtx } from '../context/CeramicCtx' import Definition from '../components/ModelView/Definition' import Instance from '../components/ModelView/Instance' import PlaygroundGraphiQL from '../components/ModelView/Playground' import styled from 'styled-components' -import { - Button, - Item, - Label, - ListBox, - Popover, - Select, -} from 'react-aria-components' -import AddIcon from '../components/icons/Add' + import { useSession } from '@us3r-network/auth-with-rainbowkit' import { Dapp } from '@us3r-network/data-model' +import { set } from 'lodash' export default function ModelView() { const { streamId } = useParams() @@ -34,6 +27,7 @@ export default function ModelView() { const session = useSession() const [modelStream, setModelStream] = useState() + const [indexing, setIndexing] = useState(false) const fetchModelInfo = useCallback( async (streamId: string) => { @@ -111,6 +105,26 @@ export default function ModelView() { [streamId, dapps, addModelToDapp, addModelToCollection] ) + const startIndex = useCallback(async () => { + if (!streamId) return + try { + const resp = await startIndexModel({ + network, + modelId: streamId, + didSession: session?.serialize(), + }) + console.log('startIndex', resp.data) + if (resp.data.code !== 0) { + throw new Error(resp.data.msg) + } + await fetchModelInfo(streamId) + } catch (error) { + console.error(error) + } finally { + setIndexing(false) + } + }, [streamId, network, session, fetchModelInfo]) + useEffect(() => { if (!streamId) return fetchModelInfo(streamId) @@ -127,27 +141,21 @@ export default function ModelView() { }) }, [dapps]) + const isIndexed = useMemo(() => { + return !!modelStream?.isIndexed + }, [modelStream]) + + const disabledKeys = useMemo(() => { + if (isIndexed) return [] + return ['Instance', 'Playground'] + }, [isIndexed]) + return ( - +
{modelStream?.streamContent?.name} - {/* - */} + {!isIndexed && } Model Definition @@ -155,17 +163,16 @@ export default function ModelView() { Model Playground
- - - - - - - - - - - + + + + + + + + + +
) } @@ -175,7 +182,7 @@ const ToolsBox = styled.div` padding-right: 20px; display: flex; align-items: center; - justify-content: space-between; + gap: 20px; > span { font-style: italic; @@ -185,6 +192,28 @@ const ToolsBox = styled.div` color: #ffffff; } + > button { + cursor: pointer; + border: none; + outline: none; + padding: 0 15px; + height: 36px; + border-radius: 100px; + background: #14171a; + font-size: 14px; + line-height: 20px; + text-align: center; + color: #a0aec0; + text-transform: capitalize; + background: #718096; + color: #14171a; + background: #ffffff; + font-family: Rubik; + font-style: normal; + font-weight: 500; + line-height: normal; + } + .add-to-dapp { border: none; border-radius: 100px; diff --git a/packages/client/scan/src/container/Models.tsx b/packages/client/scan/src/container/Models.tsx index 9d385a19..49cdfca5 100644 --- a/packages/client/scan/src/container/Models.tsx +++ b/packages/client/scan/src/container/Models.tsx @@ -167,19 +167,11 @@ export default function ModelsPage() { {!isMobile ? ( - <> - {(item.isIndexed && ( - - {item.stream_content.name} - - )) || ( -
- {item.stream_content.name} -
- )} - + + {item.stream_content.name} + ) : ( item.stream_content.name )} diff --git a/packages/client/scan/src/styles/tab.css b/packages/client/scan/src/styles/tab.css index 6bf44724..fd2fcc07 100644 --- a/packages/client/scan/src/styles/tab.css +++ b/packages/client/scan/src/styles/tab.css @@ -61,6 +61,7 @@ border-right: 3px solid var(--border-color, transparent); } } + } .dapp-title-bar .react-aria-TabList { @@ -93,13 +94,16 @@ color: var(--text-color-hover); } + + &[aria-selected='true'] { --border-color: var(--highlight-color); color: var(--text-color-selected); } &[aria-disabled] { - color: var(--text-color-disabled); + cursor: not-allowed; + color: #718096; &[aria-selected='true'] { --border-color: var(--text-color-disabled); }