Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the api to return full TODO list after adding todo #624

Merged
merged 1 commit into from
Aug 16, 2024
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
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