summaryrefslogtreecommitdiff
path: root/pages/filesystemtest.tsx
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2021-10-08 23:39:37 +0200
committerThomas F. K. Jorna <[email protected]>2021-10-08 23:39:37 +0200
commit2384b30a244c7d6477e54de5385fe7f1cc62d43a (patch)
tree55c9f82f9475249a7f91ac44e408e04e9f1c9560 /pages/filesystemtest.tsx
parentfd4edbd6a854275c10c5b21173f0875921d547d1 (diff)
feat(preview): proper file preview with api routing
Diffstat (limited to 'pages/filesystemtest.tsx')
-rw-r--r--pages/filesystemtest.tsx52
1 files changed, 0 insertions, 52 deletions
diff --git a/pages/filesystemtest.tsx b/pages/filesystemtest.tsx
deleted file mode 100644
index 4cadf0e..0000000
--- a/pages/filesystemtest.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-import React, { useEffect, useState } from 'react'
-import { Button } from '@chakra-ui/react'
-
-async function verifyPermission(fileHandle: any, readWrite: any) {
- const options: any = {}
- if (readWrite) {
- options.mode = 'readwrite'
- }
- // Check if permission was already granted. If so, return true.
- if ((await fileHandle.queryPermission(options)) === 'granted') {
- return true
- }
- // Request permission. If the user grants permission, return true.
- if ((await fileHandle.requestPermission(options)) === 'granted') {
- return true
- }
- // The user didn't grant permission, so return false.
- return false
-}
-
-export default function Testpage() {
- const [text, setText] = useState(0)
- const [dirHandle, setDirhandle] = useState<any>()
- const [perm, setPerm] = useState(false)
-
- const pick = async () => {
- const dirHandle = await window.showDirectoryPicker()
- console.log(dirHandle)
- setDirhandle(dirHandle)
- }
-
- useEffect(() => {
- ;(async () => {
- console.log(dirHandle)
- const newFileHandle = dirHandle ? await dirHandle.getFileHandle('inbox.org') : null
- const file = await newFileHandle.getFile()
- const ttext = await file.text()
- setText(ttext)
- const path = newFileHandle ? await dirHandle.resolve(newFileHandle) : null
- console.log(path)
- })()
- }, [dirHandle])
-
- return (
- <div>
- <Button onClick={() => pick()}> Press </Button>
- <p>{text}</p>
- <Button onClick={() => setPerm(verifyPermission(dirHandle, true))}>Check permission</Button>
- <p>{perm ? '👍' : '👎'}</p>
- </div>
- )
-}