Skip to content

Commit

Permalink
fix slow behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Feb 21, 2025
1 parent 9309f76 commit d0a0029
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
19 changes: 13 additions & 6 deletions src/Client/Pages/DataAnnotator/DataAnnotator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ module private DataAnnotatorHelper =
]
]

let RequestPathButton (fileName: string option, requestPath) =
let RequestPathButton (fileName: string option, requestPath, isLoading: bool) =
let fileName = defaultArg fileName "Choose File"
Html.label [
prop.className "join flex"
prop.onClick requestPath
prop.className "join flex"
prop.children [
Html.button [
prop.className "btn btn-primary join-item"
Expand All @@ -117,6 +117,13 @@ module private DataAnnotatorHelper =
prop.value fileName
prop.readOnly true
]
Html.span [
prop.className "btn btn-primary join-item btn-disabled"
prop.children [
if isLoading then
Daisy.loading []
]
]
]
]

Expand Down Expand Up @@ -346,7 +353,6 @@ type DataAnnotator =
promise {
let! content = e.text()
let dtf = DataFile.create(e.name, e.``type``, content, e.size)
setShowModal true
dtf |> Some |> UpdateDataFile |> DataAnnotatorMsg |> dispatch
}
|> Async.AwaitPromise
Expand All @@ -355,9 +361,9 @@ type DataAnnotator =
UpdateDataFile None |> DataAnnotatorMsg |> dispatch
if ref.current.IsSome then
ref.current.Value.value <- null
let requestFileFromARCitect = fun _ ->
let requestFileFromARCitect = fun (e: Browser.Types.MouseEvent) ->
e.preventDefault()
if model.PersistentStorageState.IsARCitect then
setShowModal true
Elmish.ApiCall.Start ()
|> ARCitect.RequestFile
|> ARCitectMsg
Expand All @@ -371,7 +377,8 @@ type DataAnnotator =
| true ->
DataAnnotatorHelper.DataAnnotatorButtons.RequestPathButton(
model.DataAnnotatorModel.DataFile |> Option.map _.DataFileName,
requestFileFromARCitect
requestFileFromARCitect,
model.DataAnnotatorModel.Loading
)
| false ->
DataAnnotatorHelper.DataAnnotatorButtons.UploadButton ref model uploadFileOnChange
Expand Down
2 changes: 2 additions & 0 deletions src/Client/States/DataAnnotator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ type Model =
{
DataFile: DataFile option
ParsedFile: ParsedDataFile option
Loading: bool
}
static member init () = {
DataFile = None
ParsedFile = None
Loading = false
}

type Msg =
Expand Down
6 changes: 4 additions & 2 deletions src/Client/Update.fs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ module DataAnnotator =
DataAnnotator.ParsedDataFile.fromFileBySeparator s file
)
let nextState: DataAnnotator.Model = {
DataFile = dataFile
ParsedFile = parsedFile
state with
DataFile = dataFile
ParsedFile = parsedFile
Loading = false
}
nextState, model, Cmd.none
| DataAnnotator.ToggleHeader ->
Expand Down
10 changes: 6 additions & 4 deletions src/Client/Update/ARCitectUpdate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ module ARCitect =
state, {model with FilePickerState.FileNames = paths}, Cmd.none

| ARCitect.RequestFile msg ->
log "Starting RequestFile"
match msg with
| Start () ->
let cmd =
Expand All @@ -94,19 +93,22 @@ module ARCitect =
()
(Finished >> ARCitect.RequestFile >> ARCitectMsg)
(curry GenericError Cmd.none >> DevMsg)
state, model, cmd
let nextModel =
{model with DataAnnotatorModel.Loading = true; DataAnnotatorModel.DataFile = None; DataAnnotatorModel.ParsedFile = None}
state, nextModel, cmd
| ApiCall.Finished wasSuccessful ->
let nextModel = {model with DataAnnotatorModel.Loading = false}
let cmd =
if wasSuccessful then
Cmd.none
else
GenericError (Cmd.none, exn("RequestFile failed")) |> DevMsg |> Cmd.ofMsg
state, model, cmd
state, nextModel, cmd

| ARCitect.ResponseFile file ->
let dataFile = DataAnnotator.DataFile.create(file.name, file.mimetype, file.content, file.size)
let msg = dataFile |> Some |> DataAnnotator.UpdateDataFile |> DataAnnotatorMsg
state, model , Cmd.ofMsg msg
state, {model with DataAnnotatorModel.Loading = true} , Cmd.ofMsg msg

| ARCitect.RequestPersons msg ->
match msg with
Expand Down

0 comments on commit d0a0029

Please sign in to comment.