Skip to content

Commit b511d09

Browse files
committed
Broadcast new todo to all clients
1 parent 8320fca commit b511d09

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

assets/src/actions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function fetchTodos() {
9393

9494
channel.on('new:todo', msg => {
9595
console.log('new:todo', msg);
96-
dispatch(addTodoSuccess(msg.text));
96+
dispatch(addTodoSuccess(msg.label));
9797
});
9898
};
9999
}

assets/src/components/AddTodo.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default class AddTodo extends Component {
1515
handleClick(e) {
1616
const node = this.refs.input
1717
const text = node.value.trim()
18+
if (!text) return
1819
this.props.onAddClick(text)
1920
node.value = ''
2021
}

assets/src/reducers/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function todos(state = [], action) {
2424
return [
2525
...state,
2626
{
27-
text: action.text,
27+
label: action.text,
2828
completed: false
2929
}
3030
];

lib/todo_test_web/channels/todo_channel.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ defmodule TodoTestWeb.TodoChannel do
2424
end
2525

2626
def handle_in("new:todo", payload, socket) do
27-
todo = TodoTest.Todos.create_todo(payload)
28-
broadcast socket, "ok", payload
27+
TodoTest.Todos.create_todo(payload)
28+
broadcast! socket, "new:todo", payload
2929
{:noreply, socket}
3030
end
3131

0 commit comments

Comments
 (0)