Skip to content

Commit

Permalink
#17 [front] added create storage form
Browse files Browse the repository at this point in the history
  • Loading branch information
vityaman committed Jan 23, 2024
1 parent af2e790 commit b69c722
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
8 changes: 8 additions & 0 deletions frontend/src/main/scala/ru/vityaman/mylogistics/Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ object API {
}

object Storage {
def create(name: String): Future[Unit] =
dom.ext.Ajax
.post(
url = s"${base}/storage",
data = write[StorageDraft](StorageDraft(name))
)
.map(_ => ())

def getAll(): Future[List[StorageDetailed]] =
dom.ext.Ajax
.get(s"${base}/storage")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ru.vityaman.mylogistics.model

import upickle.default._

final case class StorageDraft(
name: String
)

object StorageDraft {
implicit val rw: ReadWriter[StorageDraft] = macroRW[StorageDraft]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ru.vityaman.mylogistics.view

import ru.vityaman.mylogistics.API

import scala.concurrent.ExecutionContext.Implicits.global
import scala.util._

import com.raquo.laminar.api.L._
import org.scalajs.dom

object CreateStorageForm {
def apply(): HtmlElement = {
val name: Var[String] = Var("")

val create = () => {
API.Storage
.create(name.now())
.onComplete {
case Failure(_) => dom.window.alert("Sad things happened... :.)")
case Success(_) => dom.window.alert("Created, yoyoyo!")
}
}

div(
display.flex,
flexDirection.row,
justifyContent.center,
div(
margin.percent(1),
a("Name: "),
input(onInput.mapToValue --> name)
),
div(
margin.percent(1),
button(typ("button"), "Create", onClick --> (_ => create()))
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ object Window {
h2("Storages"),
div(StorageList(storage.storages.signal))
),
div(
h2("Create Storage"),
div(CreateStorageForm())
),
div(
h2("Storage Cells"),
div(AddCellForm())
Expand Down

0 comments on commit b69c722

Please sign in to comment.