fix: reordering bugs and UX fixes (#2948)
This commit is contained in:
46
packages/hoppscotch-common/src/newstore/reordering.ts
Normal file
46
packages/hoppscotch-common/src/newstore/reordering.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { distinctUntilChanged, pluck } from "rxjs"
|
||||
import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
|
||||
|
||||
type ReorderingItem =
|
||||
| { type: "collection"; id: string; parentID: string | null }
|
||||
| { type: "request"; id: string; parentID: string | null }
|
||||
|
||||
type CurrentReorderingState = {
|
||||
currentReorderingItem: ReorderingItem
|
||||
}
|
||||
|
||||
const initialState: CurrentReorderingState = {
|
||||
currentReorderingItem: {
|
||||
type: "collection",
|
||||
id: "",
|
||||
parentID: "",
|
||||
},
|
||||
}
|
||||
|
||||
const dispatchers = defineDispatchers({
|
||||
changeCurrentReorderStatus(
|
||||
_,
|
||||
{ reorderItem }: { reorderItem: ReorderingItem }
|
||||
) {
|
||||
return {
|
||||
currentReorderingItem: reorderItem,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export const currentReorderStore = new DispatchingStore(
|
||||
initialState,
|
||||
dispatchers
|
||||
)
|
||||
|
||||
export const currentReorderingStatus$ = currentReorderStore.subject$.pipe(
|
||||
pluck("currentReorderingItem"),
|
||||
distinctUntilChanged()
|
||||
)
|
||||
|
||||
export function changeCurrentReorderStatus(reorderItem: ReorderingItem) {
|
||||
currentReorderStore.dispatch({
|
||||
dispatcher: "changeCurrentReorderStatus",
|
||||
payload: { reorderItem },
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user