Conversation
| const { openModal } = useModal() | ||
|
|
||
| useEffect(() => { | ||
| if (parent.target.id === targetIdRef.current) { |
There was a problem hiding this comment.
What is parent? and what is parent.target?
There was a problem hiding this comment.
views can belong to either a folder, or a dashboard/smart view
so the parent is just a way to call the correct apis
export type ViewParent =
| { type: 'folder'; target: SerializedFolderWithBookmark }
| { type: 'smartView'; target: SerializedSmartView }
the useeffect here is used when you switch the selected dashboard/smart view so that it selects one of the new views so for example
select dashboard 1 > select dashboard1[views][0]
select dashboard 2 > useEffect select dashboard2[views][0]
|
|
||
| if (!res.err) { | ||
| const { data: dashboard } = res.data as CreateDashboardResponseBody | ||
| await createViewApi({ dashboard: dashboard.id, type: 'table' }) |
There was a problem hiding this comment.
all the current api calls already handle errors by default
if it errors, a toast message with the error message will be shown.
if it does not, then we can continue via callbacks or via the (!res.err)
in this instance the view creation is not the primary focus, the dashboard/smart view creation is.
So if the dashboard is still created normally then it will continue by closing the createDashboardModal
const createViewApi = useCallback(
async (target: CreateViewRequestBody) => {
return send(shortid.generate(), 'create', {
api: () => createView(target),
cb: ({ data }: CreateViewResponseBody) => {
updateViewsMap([data.id, data])
},
})
},
[updateViewsMap, send]
)
const send = useCallback(
async (id: string, act: string, { api, cb }) => {
const res = { err: false, error: undefined, data: undefined }
if (sendingMap.get(id)) {
return
}
setSendingMap((prev) => {
const newMap = new Map(prev)
newMap.delete(id)
newMap.set(id, act)
return newMap
})
try {
const data = await api()
res.data = data
if (cb != null) {
cb(data)
}
} catch (error) {
res.err = true
res.error = error
console.error(error)
pushApiErrorMessage(error)
}
setSendingMap((prev) => {
const newMap = new Map(prev)
newMap.delete(id)
return newMap
})
return res
},
[sendingMap, pushApiErrorMessage]
)
No description provided.