more prod changes

pull/162/head
Alex Kern 12 months ago
parent f4d4e0e857
commit 74b9ef2554
No known key found for this signature in database
GPG Key ID: EF051FACCACBEE25

@ -93,6 +93,7 @@ export function ConnectingToUploader({
</p> </p>
</div> </div>
</div> </div>
<ReturnHome />
</> </>
) )
} }

@ -1,4 +1,7 @@
'use client'
import React, { JSX } from 'react' import React, { JSX } from 'react'
import { useRotatingSpinner } from '../hooks/useRotatingSpinner'
function Pizza({ isRotating }: { isRotating?: boolean }): JSX.Element { function Pizza({ isRotating }: { isRotating?: boolean }): JSX.Element {
return ( return (
@ -1680,11 +1683,10 @@ function Arrow({ direction }: { direction: 'up' | 'down' }): JSX.Element {
export default function Spinner({ export default function Spinner({
direction, direction,
isRotating,
}: { }: {
direction: 'up' | 'down' direction: 'up' | 'down'
isRotating?: boolean
}): JSX.Element { }): JSX.Element {
const isRotating = useRotatingSpinner()
return ( return (
<div className="relative w-[300px] h-[300px]"> <div className="relative w-[300px] h-[300px]">
<Pizza isRotating={isRotating} /> <Pizza isRotating={isRotating} />

@ -1,6 +1,6 @@
'use client' 'use client'
import React, { JSX, useCallback } from 'react' import React, { JSX, useCallback, useEffect } from 'react'
import { UploadedFile, UploaderConnectionStatus } from '../types' import { UploadedFile, UploaderConnectionStatus } from '../types'
import { useWebRTCPeer } from './WebRTCProvider' import { useWebRTCPeer } from './WebRTCProvider'
import QRCode from 'react-qr-code' import QRCode from 'react-qr-code'
@ -11,6 +11,7 @@ import { useUploaderConnections } from '../hooks/useUploaderConnections'
import { CopyableInput } from './CopyableInput' import { CopyableInput } from './CopyableInput'
import { ConnectionListItem } from './ConnectionListItem' import { ConnectionListItem } from './ConnectionListItem'
import { ErrorMessage } from './ErrorMessage' import { ErrorMessage } from './ErrorMessage'
import { setRotating } from '../hooks/useRotatingSpinner'
const QR_CODE_SIZE = 128 const QR_CODE_SIZE = 128
@ -33,14 +34,18 @@ export default function Uploader({
onStop() onStop()
}, [stop, onStop]) }, [stop, onStop])
if (isLoading || !longSlug || !shortSlug) {
return <Loading text="Creating channel..." />
}
const activeDownloaders = connections.filter( const activeDownloaders = connections.filter(
(conn) => conn.status === UploaderConnectionStatus.Uploading, (conn) => conn.status === UploaderConnectionStatus.Uploading,
).length ).length
useEffect(() => {
setRotating(activeDownloaders > 0)
}, [activeDownloaders])
if (isLoading || !longSlug || !shortSlug) {
return <Loading text="Creating channel..." />
}
if (error) { if (error) {
return <ErrorMessage message={error.message} /> return <ErrorMessage message={error.message} />
} }

@ -15,6 +15,7 @@ import {
mobileVendor, mobileVendor,
mobileModel, mobileModel,
} from 'react-device-detect' } from 'react-device-detect'
import { setRotating } from './useRotatingSpinner'
const cleanErrorMessage = (errorMessage: string): string => const cleanErrorMessage = (errorMessage: string): string =>
errorMessage.startsWith('Could not connect to peer') errorMessage.startsWith('Could not connect to peer')
? 'Could not connect to the uploader. Did they close their browser?' ? 'Could not connect to the uploader. Did they close their browser?'
@ -86,6 +87,7 @@ export function useDownloader(uploaderPeerID: string): {
break break
case MessageType.Chunk: case MessageType.Chunk:
processChunk.current?.(message) processChunk.current?.(message)
setRotating(true)
break break
case MessageType.Error: case MessageType.Error:
console.error(message.error) console.error(message.error)
@ -103,6 +105,7 @@ export function useDownloader(uploaderPeerID: string): {
} }
const handleClose = () => { const handleClose = () => {
setRotating(false)
setDataConnection(null) setDataConnection(null)
setIsConnected(false) setIsConnected(false)
setIsDownloading(false) setIsDownloading(false)

@ -0,0 +1,42 @@
import { useEffect, useState } from 'react'
type RotationListener = (isRotating: boolean) => void
let isRotating = false
const listeners = new Set<RotationListener>()
export function setRotating(rotating: boolean): void {
isRotating = rotating
notifyListeners()
}
export function getRotating(): boolean {
return isRotating
}
export function addRotationListener(listener: RotationListener): void {
listeners.add(listener)
}
export function removeRotationListener(listener: RotationListener): void {
listeners.delete(listener)
}
function notifyListeners(): void {
listeners.forEach(listener => listener(isRotating))
}
export function useRotatingSpinner(): boolean {
const [rotating, setRotatingState] = useState(isRotating)
useEffect(() => {
const listener = (newRotating: boolean) => {
setRotatingState(newRotating)
}
addRotationListener(listener)
return () => removeRotationListener(listener)
}, [])
return rotating
}

@ -7,9 +7,10 @@ import {
} from '../types' } from '../types'
import { decodeMessage, Message, MessageType } from '../messages' import { decodeMessage, Message, MessageType } from '../messages'
import { getFileName } from '../fs' import { getFileName } from '../fs'
import { setRotating } from './useRotatingSpinner'
// TODO(@kern): Test for better values // TODO(@kern): Test for better values
const MAX_CHUNK_SIZE = 10 * 1024 * 1024 // 10 Mi const MAX_CHUNK_SIZE = 256 * 1024 // 256 KB
function validateOffset( function validateOffset(
files: UploadedFile[], files: UploadedFile[],

@ -2,7 +2,11 @@
export default { export default {
content: ['./src/**/*.{js,ts,jsx,tsx,mdx}'], content: ['./src/**/*.{js,ts,jsx,tsx,mdx}'],
theme: { theme: {
extend: {}, extend: {
animation: {
'spin-slow': 'spin 16s linear infinite',
},
},
}, },
plugins: [], plugins: [],
darkMode: 'class', darkMode: 'class',

Loading…
Cancel
Save