Skip to content

Commit

Permalink
Merge pull request #624 from SAFE-Stack/return-full-todo-list
Browse files Browse the repository at this point in the history
Change the api to return full TODO list after adding todo
  • Loading branch information
Larocceau authored Aug 16, 2024
2 parents 304f192 + 0c4071a commit dc30e03
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Content/default/src/Client/Index.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Model = {
type Msg =
| SetInput of string
| LoadTodos of ApiCall<unit, Todo list>
| SaveTodo of ApiCall<string, Todo>
| SaveTodo of ApiCall<string, Todo list>

let todosApi = Api.makeProxy<ITodosApi> ()

Expand Down Expand Up @@ -40,10 +40,10 @@ let update msg model =
Cmd.OfAsync.perform todosApi.addTodo todo (Finished >> SaveTodo)

{ model with Input = "" }, saveTodoCmd
| Finished todo ->
| Finished todos ->
{
model with
Todos = model.Todos |> RemoteData.map (fun todos -> todos @ [ todo ])
Todos = RemoteData.Loaded todos
},
Cmd.none

Expand Down
2 changes: 1 addition & 1 deletion Content/default/src/Server/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let todosApi ctx = {
fun todo -> async {
return
match Storage.addTodo todo with
| Ok() -> todo
| Ok() -> Storage.todos |> List.ofSeq
| Error e -> failwith e
}
}
Expand Down
2 changes: 1 addition & 1 deletion Content/default/src/Shared/Shared.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ module Todo =

type ITodosApi = {
getTodos: unit -> Async<Todo list>
addTodo: Todo -> Async<Todo>
addTodo: Todo -> Async<Todo list>
}
9 changes: 4 additions & 5 deletions Content/default/tests/Client/Client.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ let client =
<| fun _ ->
let newTodo = Todo.create "new todo"
let model, _ = init ()
let model, _ = update (LoadTodos (Finished [])) model
let model, _ = update (SaveTodo(Finished newTodo)) model
let model, _ = update (SaveTodo(Finished [ newTodo ])) model

Expect.equal
(model.Todos |> RemoteData.map _.Length |> RemoteData.defaultValue 0)
Expand All @@ -30,13 +29,13 @@ let client =

let all =
testList "All" [
//-:cnd:noEmit
//-:cnd:noEmit
#if FABLE_COMPILER // This preprocessor directive makes editor happy
Shared.Tests.shared
#endif
//+:cnd:noEmit
//+:cnd:noEmit
client
]

[<EntryPoint>]
let main _ = Mocha.runTests all
let main _ = Mocha.runTests all

0 comments on commit dc30e03

Please sign in to comment.