diff --git a/examples/my-gatsby-site/jaen-config.js b/examples/my-gatsby-site/jaen-config.js index 23f517d7..2eae373b 100644 --- a/examples/my-gatsby-site/jaen-config.js +++ b/examples/my-gatsby-site/jaen-config.js @@ -1,4 +1,5 @@ module.exports = { + remote: 'snek-at/jaen-template', plugins: { pages: { resolve: require('@snek-at/jaen-pages'), diff --git a/packages/jaen-pages/package.json b/packages/jaen-pages/package.json index d9464dd0..ad150152 100644 --- a/packages/jaen-pages/package.json +++ b/packages/jaen-pages/package.json @@ -26,6 +26,7 @@ "gatsby-plugin-image": "^1.12.0", "gatsby-plugin-sharp": "^3.12.0", "gatsby-transformer-sharp": "^3.12.0", + "graphql-tag": "^2.12.5", "immutability-helper": "^3.1.1", "ipfs-http-client": "^52.0.2", "juice": "^8.0.0", diff --git a/packages/jaen-pages/src/containers/ui/hotbar/PublishButton.tsx b/packages/jaen-pages/src/containers/ui/hotbar/PublishButton.tsx index e61854c2..7510726c 100644 --- a/packages/jaen-pages/src/containers/ui/hotbar/PublishButton.tsx +++ b/packages/jaen-pages/src/containers/ui/hotbar/PublishButton.tsx @@ -1,21 +1,68 @@ +import {useToast} from '@chakra-ui/react' +import {BifrostBridge} from '@snek-at/bridge' import {useJaenCoreContext} from '@snek-at/jaen' import {PublishButton} from '@snek-at/jaen-shared-ui/dist/components/molecules/buttons' +import {useAppDispatch} from '@snek-at/jaen/src/store' +import gql from 'graphql-tag' import React from 'react' +import {upload} from '../../../ipfs' import {withRedux} from '../../../store/withRedux' +const Bridge = new BifrostBridge({ + httpUrl: 'https://origin.snek.at/graphql' +}) + const Button: React.FC = () => { const core = useJaenCoreContext() + const toast = useToast() const isDisabled = core.getAuthState().isGuest + const publish = async () => { + const res = (await core.onPublish()) as {'jaen-pages': object} + + const url = await upload(JSON.stringify(res['jaen-pages'])) + + const publishRes = await Bridge.session.mutate<{ + jaenPublishFormPage: {result: string} + }>( + gql` + mutation JaenPublishMutation($values: GenericScalar!, $url: String!) { + jaenPublishFormPage(values: $values, url: $url) { + result + errors { + name + errors + } + } + } + `, + { + url: '/jaen-publish', + values: {git_remote: core.remote, jaendata_url: url} + } + ) + + if (publishRes.data?.jaenPublishFormPage?.result === 'OK') { + toast({ + title: 'Sucessfully published.', + status: 'success', + duration: 9000, + isClosable: true + }) + } else { + toast({ + title: 'Publish failed.', + status: 'error', + duration: 9000, + isClosable: true + }) + } + } + return ( - { - core.onPublish().then(res => console.log('PUBLISH', res)) - }} - /> + publish()} /> ) } diff --git a/packages/jaen/gatsby-browser.js b/packages/jaen/gatsby-browser.js index 55be9c12..4d05c128 100644 --- a/packages/jaen/gatsby-browser.js +++ b/packages/jaen/gatsby-browser.js @@ -5,6 +5,8 @@ export const wrapRootElement = ({element}) => { const config = require(___JAEN_CONFIG___) const plugins = config.plugins || [] + console.log("config", config) + const resolvedPlugins = Object.keys(plugins).map(key => { const plugin = plugins[key] @@ -12,6 +14,8 @@ export const wrapRootElement = ({element}) => { }) return ( - {element} + + {element} + ) } diff --git a/packages/jaen/gatsby-ssr.js b/packages/jaen/gatsby-ssr.js index 95fa543b..afa9fa1c 100644 --- a/packages/jaen/gatsby-ssr.js +++ b/packages/jaen/gatsby-ssr.js @@ -7,5 +7,11 @@ import {JaenCoreProvider} from './src' export const wrapRootElement = ({element}) => { - return {element} + // @ts-ignore + const config = require(___JAEN_CONFIG___) + return ( + + {element} + + ) } diff --git a/packages/jaen/src/context.tsx b/packages/jaen/src/context.tsx index 32e0880e..59b013be 100644 --- a/packages/jaen/src/context.tsx +++ b/packages/jaen/src/context.tsx @@ -6,7 +6,7 @@ import MainUI from './containers/MainUI' import {PluginCallbacks, getPublishValue, getUI, Plugin} from './plugin' import {store} from './store' -export type JaenCoreContextType = {} & PluginCallbacks +export type JaenCoreContextType = {remote: string} & PluginCallbacks export const JaenCoreContext = React.createContext< JaenCoreContextType | undefined >(undefined) @@ -22,11 +22,13 @@ export const useJaenCoreContext = (): JaenCoreContextType => { } type JaenCoreProviderProps = { + remote: string plugins: Plugin[] } export const JaenCoreProvider: React.FC = ({ children, + remote, plugins }) => { const ui = getUI(plugins) @@ -35,7 +37,7 @@ export const JaenCoreProvider: React.FC = ({ return ( <> - + {children} diff --git a/yarn.lock b/yarn.lock index 99827f99..9dd78ccf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13717,7 +13717,7 @@ graphql-subscriptions@^1.1.0: dependencies: iterall "^1.3.0" -graphql-tag@^2.10.3, graphql-tag@^2.12.3: +graphql-tag@^2.10.3, graphql-tag@^2.12.3, graphql-tag@^2.12.5: version "2.12.5" resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-2.12.5.tgz#5cff974a67b417747d05c8d9f5f3cb4495d0db8f" integrity sha512-5xNhP4063d16Pz3HBtKprutsPrmHZi5IdUGOWRxA2B6VF7BIRGOHZ5WQvDmJXZuPcBg7rYwaFxvQYjqkSdR3TQ==