fix: view api

This commit is contained in:
lawvs
2022-07-27 18:31:36 +08:00
parent 5b52daa030
commit bea829efd6

View File

@@ -77,10 +77,9 @@ export const useRecastView = () => {
const addView = useCallback( const addView = useCallback(
async (newView: RecastViewWithoutId) => { async (newView: RecastViewWithoutId) => {
await setViews([ const newViewWithId = { ...newView, id: genViewId() } as RecastView;
...recastViews, await setViews([...recastViews, newViewWithId]);
{ ...newView, id: genViewId() } as RecastView, return newViewWithId;
]);
}, },
[recastViews, setViews] [recastViews, setViews]
); );
@@ -88,7 +87,7 @@ export const useRecastView = () => {
const updateView = useCallback( const updateView = useCallback(
async (newView: RecastView) => { async (newView: RecastView) => {
const idx = recastViews.findIndex(v => v.id === newView.id); const idx = recastViews.findIndex(v => v.id === newView.id);
if (!idx) { if (idx === -1) {
throw new Error('Failed to find view with id ' + newView.id); throw new Error('Failed to find view with id ' + newView.id);
} }
await setViews([ await setViews([
@@ -141,7 +140,7 @@ export const useRecastView = () => {
recastViews, recastViews,
setCurrentView, setCurrentView,
addView, addView,
// updateView, updateView,
renameView, renameView,
removeView, removeView,
// TODO reorder API // TODO reorder API