Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Refactor usage of toast in storage explorer store

Joshen Lim766bd8dee68d
diff --git a/studio/localStores/storageExplorer/StorageExplorerStore.js b/studio/localStores/storageExplorer/StorageExplorerStore.js
index 124a3430b85..a8b34ed0803 100644
--- a/studio/localStores/storageExplorer/StorageExplorerStore.js
+++ b/studio/localStores/storageExplorer/StorageExplorerStore.js
@@ -542,7 +542,10 @@ class StorageExplorerStore {
// https://stackoverflow.com/a/53058574
getFilesDataTransferItems = async (items) => {
- const toastId = toast.loading('Retrieving items to upload...')
+ const toastId = this.ui.setNotification({
+ category: 'loading',
+ message: 'Retrieving items to upload...',
+ })
const files = []
const queue = []
for (const item of items) {
@@ -623,9 +626,9 @@ class StorageExplorerStore {
return file
})
- const uploadedTopLevelFolders = []
this.uploadProgress = 0
- let numberOfFilesToUpload = formattedFilesToUpload.length
+ const uploadedTopLevelFolders = []
+ const numberOfFilesToUpload = formattedFilesToUpload.length
let numberOfFilesUploadedSuccess = 0
let numberOfFilesUploadedFail = 0
@@ -732,28 +735,34 @@ class StorageExplorerStore {
if (numberOfFilesToUpload === 0) {
toast.dismiss(toastId)
} else if (numberOfFilesUploadedFail === numberOfFilesToUpload) {
- toast.error(
- `Failed to upload ${numberOfFilesToUpload} file${numberOfFilesToUpload > 1 ? 's' : ''}!`,
- { id: toastId }
- )
+ this.ui.setNotification({
+ id: toastId,
+ category: 'error',
+ message: `Failed to upload ${numberOfFilesToUpload} file${
+ numberOfFilesToUpload > 1 ? 's' : ''
+ }!`,
+ })
} else if (numberOfFilesUploadedSuccess === numberOfFilesToUpload) {
- toast.success(
- `Successfully uploaded ${numberOfFilesToUpload} file${
+ this.ui.setNotification({
+ id: toastId,
+ category: 'success',
+ message: `Successfully uploaded ${numberOfFilesToUpload} file${
numberOfFilesToUpload > 1 ? 's' : ''
}!`,
- { id: toastId }
- )
+ })
} else {
- toast.success(
- `Successfully uploaded ${numberOfFilesUploadedSuccess} out of ${numberOfFilesToUpload} file${
+ this.ui.setNotification({
+ id: toastId,
+ category: 'success',
+ message: `Successfully uploaded ${numberOfFilesUploadedSuccess} out of ${numberOfFilesToUpload} file${
numberOfFilesToUpload > 1 ? 's' : ''
}!`,
- { id: toastId }
- )
+ })
}
} catch (e) {
- console.error(e)
this.ui.setNotification({
+ id: toastId,
+ error: e,
message: 'Failed to upload files',
category: 'error',
})
@@ -1060,13 +1069,12 @@ class StorageExplorerStore {
}
downloadFile = async (file, showToast = true, returnBlob = false) => {
- let toastId
const fileName = file.name
const fileMimeType = get(file, ['metadata', 'mimetype'], null)
- if (showToast) {
- toastId = toast.loading(`Retrieving ${fileName}...`, { autoClose: false })
- }
+ const toastId = showToast
+ ? this.ui.setNotification({ category: 'loading', message: `Retrieving ${fileName}...` })
+ : undefined
const pathToFile = this.openedFolders
.slice(0, file.columnIndex)
@@ -1093,16 +1101,20 @@ class StorageExplorerStore {
link.parentNode.removeChild(link)
window.URL.revokeObjectURL(blob)
if (toastId) {
- toast.success(`Downloading ${fileName}`, {
+ this.ui.setNotification({
id: toastId,
+ category: 'success',
+ message: `Downloading ${fileName}`,
})
}
return true
} else {
- console.error('Failed to download:', fileName)
if (toastId) {
- toast.error(`Failed to download ${fileName}`, {
+ this.ui.setNotification({
+ error,
id: toastId,
+ category: 'error',
+ message: `Failed to download ${fileName}`,
})
}
return false
diff --git a/studio/pages/project/[ref]/logs/explorer/index.tsx b/studio/pages/project/[ref]/logs/explorer/index.tsx
index f166123a6f8..52d7906b166 100644
--- a/studio/pages/project/[ref]/logs/explorer/index.tsx
+++ b/studio/pages/project/[ref]/logs/explorer/index.tsx
@@ -1,5 +1,4 @@
import dayjs from 'dayjs'
-import toast from 'react-hot-toast'
import { useEffect, useState } from 'react'
import { useRouter } from 'next/router'
import { observer } from 'mobx-react-lite'
@@ -30,6 +29,8 @@ import LogsExplorerHeader from 'components/ui/Logs/LogsExplorerHeader'
export const LogsExplorerPage: NextPageWithLayout = () => {
const router = useRouter()
+ const { ui } = useStore()
+
const { ref, q, ite, its } = router.query
const [editorId, setEditorId] = useState<string>(uuidv4())
const [editorValue, setEditorValue] = useState<string>('')
@@ -221,12 +222,19 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
if (error) throw error
setSubmitting(false)
setSaveModalOpen(false)
- toast.success(`Saved "${values.name}" log query`)
+ ui.setNotification({
+ category: 'success',
+ message: `Saved "${values.name}" log query`,
+ })
} catch (error: any) {
console.error(error)
setSubmitting(false)
setSaveModalOpen(false)
- toast.error(error.message)
+ ui.setNotification({
+ error,
+ category: 'error',
+ message: `Failed to save query: ${error.message}`,
+ })
}
}}
>