Skip to content

Commit 923833b

Browse files
authored
Merge pull request #285 from DevinoSolutions/toastify-fix
toastify-fix
2 parents 7c8dbe1 + f456127 commit 923833b

File tree

11 files changed

+19
-71
lines changed

11 files changed

+19
-71
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ public
2121
/stories/Uploader.stories.js
2222

2323
# Tests
24-
coverage
24+
coverage
25+
26+
*.tgz

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "upup-react-file-uploader",
33
"author": "Devino Solutions",
44
"license": "MIT",
5-
"version": "1.4.5",
5+
"version": "1.4.6",
66
"publishConfig": {
77
"access": "public"
88
},
@@ -183,7 +183,6 @@
183183
"load-script": "^2.0.0",
184184
"pako": "^2.1.0",
185185
"react-icons": "^4.12.0",
186-
"react-toastify": "^11.0.3",
187186
"react-webcam": "^7.2.0",
188187
"tailwind-merge": "^2.6.0",
189188
"truncate": "^3.0.0",

pnpm-lock.yaml

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/frontend/UpupUploader.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client'
2+
13
import React, { forwardRef, useImperativeHandle } from 'react'
24
import { TbLoader } from 'react-icons/tb/index.js'
35
import { devinoDark, devinoLight, logoDark, logoLight } from '../assets/logos'
@@ -125,7 +127,7 @@ export default forwardRef<UpupUploaderRef, UpupUploaderProps>(
125127
href={'https://getupup.ca/'}
126128
target={'_blank'}
127129
rel="noopener noreferrer"
128-
className="upup-z-[2147483647] upup-flex upup-items-center upup-gap-[5px]"
130+
className="upup-flex upup-items-center upup-gap-[5px]"
129131
>
130132
<ShouldRender
131133
if={providerValues.props.dark}

src/frontend/components/AdapterSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function AdapterSelector() {
2020
className={cn(
2121
'upup-relative upup-flex upup-h-full upup-flex-col-reverse upup-items-center upup-justify-center upup-gap-3 upup-rounded-lg md:upup-flex-col md:upup-gap-14',
2222
{
23-
'upup-pt-[72px] md:upup-pt-0': isAddingMore,
23+
'md:upup-pt-0': isAddingMore,
2424
},
2525
)}
2626
>

src/frontend/components/FileList.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default memo(function FileList() {
1414
activeAdapter,
1515
files,
1616
upload: { proceedUpload, uploadStatus, totalProgress },
17-
props: { mini, dark, classNames, allowPreview, isProcessing },
17+
props: { dark, classNames, allowPreview, isProcessing },
1818
handleDone,
1919
handleCancel,
2020
} = useRootContext()
@@ -24,7 +24,6 @@ export default memo(function FileList() {
2424
className={cn(
2525
'upup-relative upup-flex upup-h-full upup-flex-col upup-rounded-lg upup-shadow',
2626
{
27-
'upup-pt-[72px] md:upup-pt-11': !mini,
2827
'upup-hidden': isAddingMore || activeAdapter || !files.size,
2928
},
3029
)}

src/frontend/components/MainBox.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
'use client'
2+
13
import { motion } from 'framer-motion'
24
import React from 'react'
3-
import { ToastContainer } from 'react-toastify'
4-
import 'react-toastify/dist/ReactToastify.css'
55
import { useRootContext } from '../context/RootContext'
66
import useMainBox from '../hooks/useMainBox'
77
import { cn } from '../lib/tailwind'
@@ -15,7 +15,6 @@ export default function MainBox() {
1515
files,
1616
activeAdapter,
1717
isAddingMore,
18-
toastContainerId,
1918
props: { dark },
2019
} = useRootContext()
2120
const {
@@ -32,7 +31,7 @@ export default function MainBox() {
3231
<motion.div
3332
key="adapter-selector"
3433
className={cn(
35-
'upup-relative upup-flex-1 upup-overflow-hidden upup-rounded-lg [&_.Toastify]:upup-absolute [&_.Toastify]:upup-bottom-0 [&_.Toastify]:upup-left-0 [&_.Toastify]:upup-right-0 [&_.Toastify__toast-container]:upup-relative',
34+
'upup-relative upup-flex-1 upup-overflow-hidden upup-rounded-lg',
3635
{
3736
'upup-border upup-border-[#1849D6]': absoluteHasBorder,
3837
'upup-border-[#30C5F7] dark:upup-border-[#30C5F7]':
@@ -60,20 +59,6 @@ export default function MainBox() {
6059
<AdapterSelector />
6160
</ShouldRender>
6261
<FileList />
63-
64-
<ShouldRender if={true}>
65-
<ToastContainer
66-
position="bottom-center"
67-
className="!upup-relative !upup-bottom-2 !upup-left-1/2 !upup-w-[320px] !upup-max-w-[90%] !-upup-translate-x-1/2"
68-
limit={2}
69-
theme={dark ? 'dark' : 'light'}
70-
containerId={`upup-toast-container-${toastContainerId}`}
71-
progressClassName="upup-h-0"
72-
hideProgressBar
73-
newestOnTop
74-
stacked
75-
/>
76-
</ShouldRender>
7762
</motion.div>
7863
</MyAnimatePresence>
7964
)

src/frontend/components/shared/MainBoxHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function MainBoxHeader({ handleCancel }: Readonly<Props>) {
3434
return (
3535
<div
3636
className={cn(
37-
'upup-shadow-bottom upup-absolute upup-left-0 upup-right-0 upup-top-0 upup-z-10 upup-grid upup-grid-cols-4 upup-grid-rows-2 upup-items-center upup-justify-between upup-rounded-t-lg upup-bg-black/[0.025] upup-px-3 upup-py-2 md:upup-grid-rows-1',
37+
'upup-shadow-bottom upup-left-0 upup-right-0 upup-top-0 upup-z-10 upup-grid upup-grid-cols-4 upup-grid-rows-2 upup-items-center upup-justify-between upup-rounded-t-lg upup-bg-black/[0.025] upup-px-3 upup-py-2 md:upup-grid-rows-1',
3838
{
3939
'upup-bg-white/5 dark:upup-bg-white/5': dark,
4040
},

src/frontend/context/RootContext.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export interface IRootContext {
8080

8181
upload: ContextUpload
8282
props: ContextProps
83-
toastContainerId: string
8483
}
8584

8685
const RootContext = createContext<IRootContext>({

src/frontend/hooks/useRootProvider.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
1+
import { useCallback, useMemo, useRef, useState } from 'react'
22
import {
33
TbCameraRotate,
44
TbCapture,
55
TbLoader,
66
TbPlus,
77
TbTrash,
88
} from 'react-icons/tb/index.js'
9-
import { toast } from 'react-toastify'
10-
import truncate from 'truncate'
11-
import { v4 as uuid } from 'uuid'
129
import checkFileType from '../../shared/lib/checkFileType'
1310
import {
1411
FileWithParams,
@@ -23,7 +20,6 @@ import {
2320
sizeToBytes,
2421
} from '../lib/file'
2522
import { ProviderSDK } from '../lib/storage/provider'
26-
import { cn } from '../lib/tailwind'
2723

2824
type FileProgress = {
2925
id: string
@@ -33,9 +29,6 @@ type FileProgress = {
3329

3430
export type FilesProgressMap = Record<string, FileProgress>
3531

36-
const toastClassName =
37-
'upup-px-4 upup-pr-6 upup-py-3 upup-text-center !upup-mb-0 upup-min-h-fit upup-shadow-lg [&_button]:upup-top-1/2 [&_button]:-upup-translate-y-1/2'
38-
3932
export default function useRootProvider({
4033
accept = '*',
4134
mini = false,
@@ -81,7 +74,6 @@ export default function useRootProvider({
8174
const [filesProgressMap, setFilesProgressMap] = useState<FilesProgressMap>(
8275
{} as FilesProgressMap,
8376
)
84-
const [toastContainerId, setToastContainerId] = useState<string>('')
8577
const [uploadError, setUploadError] = useState('')
8678

8779
const limit = useMemo(
@@ -105,24 +97,15 @@ export default function useRootProvider({
10597
setUploadError(message)
10698

10799
if (errorHandler) errorHandler(message)
108-
else
109-
toast.error(truncate(message, 75), {
110-
containerId: toastContainerId,
111-
className: cn(toastClassName, 'upup-text-red-500'),
112-
})
113100
},
114-
[errorHandler, toastContainerId],
101+
[errorHandler],
115102
)
116103

117104
const onWarn = useCallback(
118-
(message: string) =>
119-
warningHandler
120-
? warningHandler(message)
121-
: toast.warn(message, {
122-
containerId: toastContainerId,
123-
className: cn(toastClassName, 'upup-text-yellow-500'),
124-
}),
125-
[warningHandler, toastContainerId],
105+
(message: string) => {
106+
if (warningHandler) warningHandler(message)
107+
},
108+
[warningHandler],
126109
)
127110
function isFileWithParamsArray(
128111
files: File[] | FileWithParams[],
@@ -335,10 +318,6 @@ export default function useRootProvider({
335318
setSelectedFilesMap(new Map())
336319
setFilesProgressMap({})
337320
}, [])
338-
useEffect(() => {
339-
if (!toastContainerId.length && (!errorHandler || !warningHandler))
340-
setToastContainerId(uuid())
341-
}, [errorHandler, warningHandler, toastContainerId])
342321

343322
return {
344323
inputRef,
@@ -356,7 +335,6 @@ export default function useRootProvider({
356335
handleFileRemove,
357336
oneDriveConfigs: driveConfigs?.oneDrive,
358337
googleDriveConfigs: driveConfigs?.googleDrive,
359-
toastContainerId,
360338
upload: {
361339
totalProgress,
362340
filesProgressMap,

0 commit comments

Comments
 (0)