Skip to content

Commit

Permalink
refactor: decaf
Browse files Browse the repository at this point in the history
  • Loading branch information
Cafe137 committed Nov 4, 2024
1 parent b69c1b3 commit 384bb49
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/pages/fdp/FdpPod.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FdpStorage } from '@fairdatasociety/fdp-storage'
import { Strings } from 'cafe-utility'
import { useState } from 'react'
import { CafeReactFs } from '../../react-fs/CafeReactFs'
import { FsItem, FsItemType } from '../../react-fs/CafeReactType'
import { joinUrl } from '../../react-fs/Utility'

interface Props {
fdp: FdpStorage
Expand Down Expand Up @@ -44,7 +44,7 @@ export function FdpPod({ fdp, name }: Props) {
}
for (const file of Array.from(input.files)) {
const data = await file.arrayBuffer()
await fdp.file.uploadData(name, Strings.joinUrl(path, file.name), new Uint8Array(data))
await fdp.file.uploadData(name, joinUrl(path, file.name), new Uint8Array(data))
}
reload()
resolve()
Expand All @@ -58,7 +58,7 @@ export function FdpPod({ fdp, name }: Props) {
if (!newDirectoryName) {
return
}
await fdp.directory.create(name, Strings.joinUrl(path, newDirectoryName))
await fdp.directory.create(name, joinUrl(path, newDirectoryName))
reload()
}}
// eslint-disable-next-line require-await
Expand Down
4 changes: 2 additions & 2 deletions src/pages/fdp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Bee } from '@ethersphere/bee-js'
import { FdpStorage } from '@fairdatasociety/fdp-storage'
import { Pod } from '@fairdatasociety/fdp-storage/dist/pod/types'
import { CircularProgress, Typography } from '@material-ui/core'
import { Strings } from 'cafe-utility'
import { useSnackbar } from 'notistack'
import { ReactElement, useEffect, useState } from 'react'
import ImportIcon from 'remixicon-react/AddBoxLineIcon'
import PlusCircle from 'remixicon-react/AddCircleLineIcon'
import { SwarmButton } from '../../components/SwarmButton'
import { joinUrl } from '../../react-fs/Utility'
import { ManifestJs } from '../../utils/manifest'
import { FdpLogin } from './FdpLogin'
import { FdpPods } from './FdpPods'
Expand Down Expand Up @@ -124,7 +124,7 @@ export default function FDP(): ReactElement {
const entries = await manifestJs.getHashes(importHash)
await fdp.personalStorage.create(name)
for (const [path, hash] of Object.entries(entries)) {
await fdp.file.uploadData(name, Strings.joinUrl('/', path), await bee.downloadData(hash))
await fdp.file.uploadData(name, joinUrl('/', path), await bee.downloadData(hash))
}
const pods = await fdp.personalStorage.list()
setPods(pods.pods)
Expand Down
6 changes: 3 additions & 3 deletions src/react-fs/CafeReactFsFile.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Strings } from 'cafe-utility'
import { useState } from 'react'
import { CafeReactFsDelete } from './CafeReactFsDelete'
import { CafeReactFsLoading } from './CafeReactFsLoading'
import { CafeReactFsName } from './CafeReactFsName'
import { VirtualFile } from './CafeReactType'
import { joinUrl } from './Utility'

interface Props {
path: string
Expand All @@ -24,12 +24,12 @@ export function CafeReactFsFile({ path, file, download, deleteFile, backgroundCo
function proxyDelete() {
setLoading(true)

return deleteFile(Strings.joinUrl(path, file.name)).finally(() => setLoading(false))
return deleteFile(joinUrl(path, file.name)).finally(() => setLoading(false))
}

return (
<div
onClick={() => download(Strings.joinUrl(path, file.name))}
onClick={() => download(joinUrl(path, file.name))}
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
style={{
Expand Down
4 changes: 2 additions & 2 deletions src/react-fs/CafeReactFsPath.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Strings } from 'cafe-utility'
import { joinUrl } from './Utility'

interface Props {
pathParts: string[]
Expand All @@ -14,7 +14,7 @@ export function CafeReactFsPath({ pathParts, jumpToDirectory, backgroundColor, r
if (absolutePaths.length === 0) {
absolutePaths.push(pathPart)
} else {
absolutePaths.push(Strings.joinUrl(absolutePaths[absolutePaths.length - 1], pathPart))
absolutePaths.push(joinUrl(absolutePaths[absolutePaths.length - 1], pathPart))
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/react-fs/Utility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function joinUrl(...parts: unknown[]): string {
return parts
.filter(x => x)
.join('/')
.replace(/(?<!:)\/+/g, '/')
}

0 comments on commit 384bb49

Please sign in to comment.