Skip to content

Commit

Permalink
use NcReferenceList in whiteboard
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <[email protected]>
  • Loading branch information
grnd-alt committed Jul 18, 2024
1 parent 3a47730 commit 2932ae5
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import type {
ExcalidrawInitialDataState,
} from '@excalidraw/excalidraw/types/types'
import { Collab } from './collaboration/collab'
import Embeddable from './Embeddable'
import type { NonDeletedExcalidrawElement } from '@excalidraw/excalidraw/types/element/types'

Check failure on line 24 in src/App.tsx

View workflow job for this annotation

GitHub Actions / NPM lint

'/home/runner/actions-runner/_work/whiteboard/whiteboard/node_modules/@excalidraw/excalidraw/types/element/types.d.ts' imported multiple times
import type { ResolvablePromise } from '@excalidraw/excalidraw/types/utils'
import type { NonDeletedExcalidrawElement } from '@excalidraw/excalidraw/types/element/types'

Check failure on line 26 in src/App.tsx

View workflow job for this annotation

GitHub Actions / NPM lint

'/home/runner/actions-runner/_work/whiteboard/whiteboard/node_modules/@excalidraw/excalidraw/types/element/types.d.ts' imported multiple times
interface WhiteboardAppProps {
Expand Down Expand Up @@ -122,10 +124,16 @@ export default function App({ fileId, isEmbedded }: WhiteboardAppProps) {
)
}

const renderEmbeddableTest = (element: NonDeletedExcalidrawElement) => {
return React.createElement(Embeddable,{react: React, url: element.link})

Check failure on line 128 in src/App.tsx

View workflow job for this annotation

GitHub Actions / NPM lint

A space is required after ','

Check failure on line 128 in src/App.tsx

View workflow job for this annotation

GitHub Actions / NPM lint

A space is required after '{'

Check failure on line 128 in src/App.tsx

View workflow job for this annotation

GitHub Actions / NPM lint

A space is required before '}'
}

return (
<div className="App">
<div className="excalidraw-wrapper">
<Excalidraw
validateEmbeddable={()=>true}

Check failure on line 135 in src/App.tsx

View workflow job for this annotation

GitHub Actions / NPM lint

Missing space before =>

Check failure on line 135 in src/App.tsx

View workflow job for this annotation

GitHub Actions / NPM lint

Missing space after =>
renderEmbeddable={(element) => renderEmbeddableTest(element)}
excalidrawAPI={(api: ExcalidrawImperativeAPI) => {
console.log(api)
console.log('Setting API')
Expand Down
20 changes: 20 additions & 0 deletions src/Embeddable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import VueWrapper from "./VueWrapper"

Check failure on line 1 in src/Embeddable.tsx

View workflow job for this annotation

GitHub Actions / NPM lint

Strings must use singlequote

/**

Check warning on line 3 in src/Embeddable.tsx

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @param "props" declaration
*
*/
export default function(props) {
const {react} = props

Check failure on line 7 in src/Embeddable.tsx

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 1 tab but found 4 spaces

Check failure on line 7 in src/Embeddable.tsx

View workflow job for this annotation

GitHub Actions / NPM lint

A space is required after '{'
let testing = react.useRef('')

react.useEffect(()=> {
fetch("/").then(async resp => {
testing.current = await resp.text()
})
},[])

const referenceProps = {text: props.url, limit: "1", interactive: true}
return (
<VueWrapper componentProps={referenceProps} />
)
}
47 changes: 47 additions & 0 deletions src/VueWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { NcReferenceList } from '@nextcloud/vue/dist/Components/NcRichText.js'
import Vue from 'vue'

const VueWrapper = function(
{ componentProps }) {
const vueRef = React.useRef(null)
const [vueInstance, setVueInstance] = React.useState(undefined)

React.useEffect(() => {
/**
*
*/
async function createVueInstance() {
}

createVueInstance()

setVueInstance(new Vue({
el: vueRef.current,
data() {
return {
props: componentProps,
}
},
render(h) {
return h(NcReferenceList, {
props: this.props,
})
},
}))

return () => {
vueInstance?.$destroy()
}
}, [])

React.useEffect(() => {
if (vueInstance) {
const keys = Object.keys(componentProps)
keys.forEach(key => vueInstance.props[key] = componentProps[key])
}
}, [Object.values(componentProps)])

return <div id="vue-component" ref={vueRef}></div>
}

export default VueWrapper

0 comments on commit 2932ae5

Please sign in to comment.