Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC: uploading files to nextcloud #278

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
\.idea/

/build/
/backup/
/js/
/dist/
/css/
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The official whiteboard app for Nextcloud. It allows users to create and share w
<screenshot>https://raw.githubusercontent.com/nextcloud/whiteboard/main/screenshots/screenshot1.png</screenshot>

<dependencies>
<nextcloud min-version="28" max-version="30"/>
<nextcloud min-version="28" max-version="31"/>
</dependencies>

<settings>
Expand Down
2 changes: 2 additions & 0 deletions src/collaboration/collab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Portal } from './Portal'
import { restoreElements } from '@excalidraw/excalidraw'
import { throttle } from 'lodash'
import { hashElementsVersion, reconcileElements } from './util'
import { registerFilesHandler } from '../files/files.ts'

export class Collab {

Expand All @@ -28,6 +29,7 @@ export class Collab {
this.setViewModeEnabled = setViewModeEnabled

this.portal = new Portal(`${fileId}`, this, publicSharingToken)
registerFilesHandler(this.excalidrawAPI, this)
}

async startCollab() {
Expand Down
110 changes: 110 additions & 0 deletions src/files/SideBarDownload.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { createRoot } from 'react-dom'
import { type JSX } from 'react'
import { type Meta } from './files'
import { mdiDownloadBox } from '@mdi/js'
import { Icon } from '@mdi/react'

/**
* renders the html button for file downloads
* @param meta file data
* @param onClick onClick callback
* @return {JSX.Element} rendered Button JSX
*/
function renderDownloadButton(meta: Meta, onClick: () => void): JSX.Element {
const iconUrl = window.OC.MimeType.getIconUrl(meta.type)
return (
<div
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
padding: '10px',
}}>
<img
src={iconUrl}
style={{
width: '50px',
height: '50px',
marginBottom: '10px',
}}
/>
<span
style={{
marginBottom: '5px',
textAlign: 'center',
fontWeight: 'bold',
}}>
{meta.name}
</span>
<button
onClick={onClick}
style={{ textAlign: 'center', fontWeight: 'bold' }}>
Download
<Icon
path={mdiDownloadBox}
size={1.5}
style={{ verticalAlign: 'middle' }}
/>
</button>
</div>
)
}

/**
* removes the download button from the sidebar
* makes all default excalidraw settings visible again
* @return {void}
*/
export function ResetDownloadButton() {
const sideBar = document.getElementsByClassName('App-menu__left')[0]
if (sideBar === undefined) {
return
}
const panelColumn = sideBar.querySelector('.panelColumn') as HTMLElement
if (panelColumn) {
panelColumn.style.display = ''
}
const downloadButton = document.getElementsByClassName('nc-download')[0]
sideBar.removeChild(downloadButton)
}

/**
* clears the excalidraw sidebar as soon as it appears
* inserts a download button with the file name instead
* @param meta file data
* @param onClick onClick callback
*/
export function InsertDownloadButton(meta: Meta, onClick: () => void) {
const callback = () => {
const sideBar = document.getElementsByClassName('App-menu__left')[0]
if (sideBar === undefined) {
return
}
observer.disconnect()
const newElement = document.createElement('div')
newElement.classList.add('nc-download')
const root = createRoot(newElement)
root.render(renderDownloadButton(meta, onClick))

// hide all excalidraw settings
const panelColumn = sideBar.querySelector('.panelColumn') as HTMLElement
if (panelColumn) {
panelColumn.style.display = 'none'
}

sideBar.appendChild(newElement)
}

const observer = new MutationObserver(callback)

const sideBar = document.getElementsByClassName('App-menu__left')[0]
if (sideBar !== undefined) {
callback()
} else {
observer.observe(document.body, { childList: true, subtree: true })
}
}
Loading
Loading