Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/zui/src/core/view-handler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {Dispatch, State, Store} from "src/js/state/types"
import {ipc} from "src/modules/bullet/view"
import {invoke} from "./invoke"
import toast from "react-hot-toast"

type Selector = (state: State, ...args: any) => any

export class ViewHandler {
static store: Store
static invoke = invoke
protected invoke = invoke
protected toast = toast

protected get store() {
return ViewHandler.store
Expand Down
18 changes: 8 additions & 10 deletions apps/zui/src/views/new-pool-modal/controller.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import {poolPath} from "src/app/router/utils/paths"
import {createHandler} from "src/core/handlers"
import {ViewHandler} from "src/core/view-handler"
import Tabs from "src/js/state/Tabs"
import {getFormData} from "src/util/get-form-data"

const createPool = createHandler(async ({invoke, dispatch, toast}, data) => {
const id = await invoke("pools.create", data.name, data)
dispatch(Tabs.activateUrl(poolPath(id)))
toast.success("Pool Created")
})

export class NewPoolModalController {
constructor(private close, private state) {}
export class NewPoolModalController extends ViewHandler {
constructor(private close, private state) {
super()
}

async onSubmit(e) {
try {
const data = getFormData(e)
createPool(data)
const id = await this.invoke("pools.create", data.name, data)
this.dispatch(Tabs.activateUrl(poolPath(id)))
this.toast.success("Pool Created")
this.close()
} catch (e) {
this.state.setError(e)
Expand Down