create-fluxstack 1.20.1 → 1.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LLMD/resources/live-components.md +103 -57
- package/LLMD/resources/live-rooms.md +187 -88
- package/README.md +27 -25
- package/app/client/.live-stubs/LiveCounter.js +4 -4
- package/app/client/src/App.tsx +12 -13
- package/app/client/src/components/AppLayout.tsx +290 -252
- package/app/client/src/components/BackButton.tsx +16 -13
- package/app/client/src/components/DemoPage.tsx +135 -22
- package/app/client/src/index.css +21 -11
- package/app/client/src/live/AuthDemo.tsx +270 -333
- package/app/client/src/live/CounterDemo.tsx +151 -206
- package/app/client/src/live/FormDemo.tsx +140 -119
- package/app/client/src/live/PingPongDemo.tsx +180 -202
- package/app/client/src/live/RoomChatDemo.tsx +397 -374
- package/app/client/src/pages/HomePage.tsx +170 -104
- package/app/server/live/LiveCounter.ts +71 -68
- package/app/server/live/LiveSharedCounter.ts +18 -12
- package/app/server/live/auto-generated-components.ts +1 -3
- package/app/server/live/rooms/CounterRoom.ts +15 -10
- package/core/client/index.ts +0 -3
- package/core/client/state/createStore.ts +88 -88
- package/core/client/state/index.ts +5 -5
- package/core/server/live/auto-generated-components.ts +1 -3
- package/core/utils/version.ts +1 -1
- package/package.json +5 -5
- package/tsconfig.json +7 -6
- package/app/client/src/components/LiveUploadWidget.tsx +0 -200
- package/app/client/src/live/UploadDemo.tsx +0 -21
- package/app/server/live/LiveUpload.ts +0 -96
- package/core/client/hooks/useLiveUpload.ts +0 -70
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react'
|
|
2
|
-
import { Live, useLiveChunkedUpload } from '@fluxstack/live-react'
|
|
3
|
-
import type { LiveChunkedUploadOptions } from '@fluxstack/live-react'
|
|
4
|
-
import type { FileUploadCompleteResponse } from '@fluxstack/live'
|
|
5
|
-
import { LiveUpload } from '@server/live/LiveUpload'
|
|
6
|
-
|
|
7
|
-
export interface UseLiveUploadOptions {
|
|
8
|
-
live?: {
|
|
9
|
-
room?: string
|
|
10
|
-
userId?: string
|
|
11
|
-
autoMount?: boolean
|
|
12
|
-
debug?: boolean
|
|
13
|
-
}
|
|
14
|
-
upload?: LiveChunkedUploadOptions
|
|
15
|
-
onProgress?: (progress: number, bytesUploaded: number, totalBytes: number) => void
|
|
16
|
-
onComplete?: (response: FileUploadCompleteResponse) => void
|
|
17
|
-
onError?: (error: string) => void
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function useLiveUpload(options: UseLiveUploadOptions = {}) {
|
|
21
|
-
const { live: liveOptions, upload: uploadOptions, onProgress, onComplete, onError } = options
|
|
22
|
-
|
|
23
|
-
const live = Live.use(LiveUpload, {
|
|
24
|
-
initialState: LiveUpload.defaultState,
|
|
25
|
-
...liveOptions
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
const mergedUploadOptions = useMemo<LiveChunkedUploadOptions>(() => {
|
|
29
|
-
return {
|
|
30
|
-
allowedTypes: [],
|
|
31
|
-
maxFileSize: 500 * 1024 * 1024,
|
|
32
|
-
adaptiveChunking: true,
|
|
33
|
-
fileUrlResolver: (fileUrl) => fileUrl.startsWith('/uploads/') ? `/api${fileUrl}` : fileUrl,
|
|
34
|
-
onProgress,
|
|
35
|
-
onComplete,
|
|
36
|
-
onError,
|
|
37
|
-
...uploadOptions
|
|
38
|
-
}
|
|
39
|
-
}, [onProgress, onComplete, onError, uploadOptions])
|
|
40
|
-
|
|
41
|
-
const upload = useLiveChunkedUpload(live, mergedUploadOptions)
|
|
42
|
-
|
|
43
|
-
const startUpload = useMemo(() => {
|
|
44
|
-
return async (file: File) => {
|
|
45
|
-
if (!live.$connected || !live.$componentId) {
|
|
46
|
-
const msg = 'WebSocket nao conectado. Tente novamente.'
|
|
47
|
-
onError?.(msg)
|
|
48
|
-
await live.failUpload({ error: msg })
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
await upload.uploadFile(file)
|
|
52
|
-
}
|
|
53
|
-
}, [live, upload, onError])
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
live,
|
|
57
|
-
state: live.$state,
|
|
58
|
-
status: live.$state.status,
|
|
59
|
-
connected: live.$connected,
|
|
60
|
-
componentId: live.$componentId,
|
|
61
|
-
uploading: upload.uploading,
|
|
62
|
-
progress: upload.progress,
|
|
63
|
-
bytesUploaded: upload.bytesUploaded,
|
|
64
|
-
totalBytes: upload.totalBytes,
|
|
65
|
-
error: live.$state.error,
|
|
66
|
-
startUpload,
|
|
67
|
-
cancelUpload: upload.cancelUpload,
|
|
68
|
-
reset: upload.reset
|
|
69
|
-
}
|
|
70
|
-
}
|