diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 86c8870e..6e1cdde0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,3 +16,15 @@ jobs: run: | yarn install yarn test + test-hooks: + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '15' + - name: 'Test hooks' + working-directory: ./packages/hooks + run: | + yarn install + yarn test diff --git a/examples/frontend/package.json b/examples/frontend/package.json index 83bb225e..98ef96d9 100644 --- a/examples/frontend/package.json +++ b/examples/frontend/package.json @@ -8,8 +8,8 @@ "start": "next start" }, "dependencies": { - "@cura/components": "0.0.12", - "@cura/hooks": "0.0.4", + "@cura/components": "0.0.14", + "@cura/hooks": "0.0.6", "@runwayml/hosted-models": "^0.3.0", "@theme-ui/color": "^0.8.4", "@theme-ui/match-media": "^0.6.0", diff --git a/examples/frontend/pages/cc/[project]/[id].tsx b/examples/frontend/pages/cc/[project]/[id].tsx index cff162cb..d4df3ce3 100644 --- a/examples/frontend/pages/cc/[project]/[id].tsx +++ b/examples/frontend/pages/cc/[project]/[id].tsx @@ -5,7 +5,7 @@ import { Button, Text } from 'theme-ui' import { utils } from 'near-api-js' import { useRouter } from 'next/router' import Layout from '../../../containers/Layout' -import { Bidders, RenderIframe, CreatorShare } from '@cura/components' +import { Bidders, CreatorShare, MediaObject } from '@cura/components' import { alertMessageState, indexLoaderState } from '../../../state/recoil' import { useSetRecoilState } from 'recoil' import { mapPathToProject } from 'utils/path-to-project' @@ -13,7 +13,6 @@ import { getFrameWidth } from 'utils/frame-width' import { useNFTContract, useNFTMethod, useMarketMethod } from '@cura/hooks' import { useStatusUpdate } from 'utils/hooks-helpers' -const CONTRACT_VIEW_GAS = utils.format.parseNearAmount('0.00000000010') // 100 Tgas const CONTRACT_BURN_GAS = utils.format.parseNearAmount('0.00000000029') // 290 Tgas const MARKET_ACCEPT_BID_GAS = utils.format.parseNearAmount('0.00000000025') // 250 Tgas const YOCTO_NEAR = utils.format.parseNearAmount('0.000000000000000000000001') @@ -39,7 +38,7 @@ const CCProjectID = ({}) => { token_id: router.query.id, limit: 2, }, - CONTRACT_VIEW_GAS, + undefined, updateStatus ) @@ -107,9 +106,10 @@ const CCProjectID = ({}) => { }} > {media && ( - )} diff --git a/examples/frontend/pages/cc/[project]/create.tsx b/examples/frontend/pages/cc/[project]/create.tsx index db5d8cb8..88c1cf87 100644 --- a/examples/frontend/pages/cc/[project]/create.tsx +++ b/examples/frontend/pages/cc/[project]/create.tsx @@ -6,7 +6,7 @@ import { utils } from 'near-api-js' import { useRouter } from 'next/router' import Layout from '../../../containers/Layout' -import { CreatorShare, RenderIframe } from '@cura/components' +import { CreatorShare } from '@cura/components' import { alertMessageState, indexLoaderState } from '../../../state/recoil' import { useSetRecoilState } from 'recoil' import { useNFTContract } from '@cura/hooks' @@ -136,10 +136,13 @@ const MLProjectCreate = ({}) => { }} > {creativeCode && ( - + height={frameDimension} + frameBorder="0" + scrolling="no" + > )}
{ }} > {randomDesign?.metadata?.media && ( - )}
@@ -141,10 +142,7 @@ const Explore = ({}) => { alignItems: 'center', }} > - +
{ }} > {metadata?.media && ( - )}
diff --git a/examples/frontend/pages/ml/[project]/[id].tsx b/examples/frontend/pages/ml/[project]/[id].tsx index dae9208f..dcc2997b 100644 --- a/examples/frontend/pages/ml/[project]/[id].tsx +++ b/examples/frontend/pages/ml/[project]/[id].tsx @@ -6,15 +6,13 @@ import { Button, Flex, Box, Text } from 'theme-ui' import { utils } from 'near-api-js' import { useRouter } from 'next/router' import Layout from '../../../containers/Layout' -import { CreatorShare } from '@cura/components' -import { Bidders } from '@cura/components' +import { CreatorShare, Bidders, MediaObject } from '@cura/components' import { alertMessageState, indexLoaderState } from '../../../state/recoil' import { useRecoilValue, useSetRecoilState } from 'recoil' import { useNFTContract, useNFTMethod, useMarketMethod } from '@cura/hooks' import { accountState } from 'state/account' import { getFrameWidth } from 'utils/frame-width' import { useStatusUpdate } from 'utils/hooks-helpers' -const CONTRACT_VIEW_GAS = utils.format.parseNearAmount('0.00000000010') // 100 Tgas const CONTRACT_BURN_GAS = utils.format.parseNearAmount('0.00000000029') // 290 Tgas const MARKET_ACCEPT_BID_GAS = utils.format.parseNearAmount('0.00000000025') // 250 Tgas const YOCTO_NEAR = utils.format.parseNearAmount('0.000000000000000000000001') @@ -42,7 +40,7 @@ const MLProject = ({}) => { token_id: router.query.id, limit: 2, }, - CONTRACT_VIEW_GAS, + null, updateStatus ) @@ -110,9 +108,10 @@ const MLProject = ({}) => { }} > {media && ( - )} diff --git a/examples/frontend/pages/ml/[project]/create.tsx b/examples/frontend/pages/ml/[project]/create.tsx index 1bc3bbc5..0720ed75 100644 --- a/examples/frontend/pages/ml/[project]/create.tsx +++ b/examples/frontend/pages/ml/[project]/create.tsx @@ -6,7 +6,7 @@ import { utils } from 'near-api-js' import { useRouter } from 'next/router' import Layout from '../../../containers/Layout' import { HostedModel } from '@runwayml/hosted-models' -import { CreatorShare } from '@cura/components' +import { CreatorShare, MediaObject } from '@cura/components' import { alertMessageState, indexLoaderState } from '../../../state/recoil' import { useRecoilValue, useSetRecoilState } from 'recoil' import { useNFTContract } from '@cura/hooks' @@ -170,7 +170,7 @@ const MLProjectCreate = ({}) => { width: frameDimension, }} > - +
{ }} > {randomDesign?.metadata.media && ( - )}
@@ -138,10 +144,7 @@ const Explore = ({}) => { alignItems: 'center', }} > - +
{ }, }} > -
diff --git a/examples/frontend/pages/share/create.tsx b/examples/frontend/pages/share/create.tsx index 6a807921..7eeb520e 100644 --- a/examples/frontend/pages/share/create.tsx +++ b/examples/frontend/pages/share/create.tsx @@ -5,7 +5,7 @@ import { useState } from 'react' import { Button, Text } from 'theme-ui' import { utils } from 'near-api-js' import Layout from '../../containers/Layout' -import { CreatorShare, RenderIframe } from '@cura/components' +import { CreatorShare } from '@cura/components' import { alertMessageState, indexLoaderState } from '../../state/recoil' import { useSetRecoilState } from 'recoil' import { useNFTContract } from '@cura/hooks' @@ -128,10 +128,13 @@ const Create = ({}) => { }} > {creativeCode && ( - + height={frameDimension} + frameBorder="0" + scrolling="no" + > )}
{ }} > {randomDesign.metadata.media && ( - )}
@@ -134,10 +135,7 @@ const Explore = ({}) => { alignItems: 'center', }} > - +
{ }} > {media?.[0]?.metadata?.media && ( - )}
diff --git a/packages/components/package.json b/packages/components/package.json index dad8018a..5c714350 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -1,6 +1,6 @@ { "name": "@cura/components", - "version": "0.0.12", + "version": "0.0.14", "description": "Components for front-ends on NEAR blockchain", "source": "src/index.ts", "main": "dist/index.js", @@ -18,6 +18,8 @@ "author": "Yassine", "license": "MIT", "dependencies": { + "@cura/hooks": "0.0.6", + "@theme-ui/match-media": "^0.12.0", "@theme-ui/presets": "^0.6.0", "near-api-js": "^0.42.0", "react": "^17.0.1", diff --git a/packages/components/src/MediaObject.tsx b/packages/components/src/MediaObject.tsx new file mode 100644 index 00000000..c38e1573 --- /dev/null +++ b/packages/components/src/MediaObject.tsx @@ -0,0 +1,106 @@ +// @ts-nocheck +/** @jsxImportSource theme-ui */ + +import { useNFTContentType } from '@cura/hooks' +import { Placeholder } from './Placeholder' + +type mediaObjectProps = { + mediaURI: string + width?: number | string + height?: number | string + loading?: boolean + autoPlay?: boolean +} + +function Text({ width, height, content }) { + return ( +
+            {content}
+        
+ ) +} + +function Video({ mediaURI, width, height, autoPlay }: mediaObjectProps) { + return ( + + ) +} + +function Audio({ mediaURI }: mediaObjectProps) { + return +} + +function Image({ mediaURI, width, height }: mediaObjectProps) { + return ( + + ) +} + +function Iframe({ mediaURI, width, height }: mediaObjectProps) { + return ( + + ) +} + +export function MediaObject(props: mediaObjectProps) { + const { loading, data, content } = useNFTContentType(props.mediaURI) + + if (props.loading || loading) { + return ( + + ) + } + switch (data) { + case 'image': + return + + case 'video': + return