diff --git a/src/actions/index.ts b/src/actions/index.ts index f29b5ff..b81dec6 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -42,6 +42,15 @@ export function fetchNotes() { } } +export function addNoteAction(note: any) { + return { + type: ADD_NOTE, + id: note.id, + title: note.title, + content: note.content + } +} + /** * Add new note * @param title Note title @@ -51,20 +60,21 @@ export function addNote(title: string, content: string) { return (dispatch: any) => { const noteId = generateNoteId(); const note = {id: noteId, title: title, content: content}; - return saveNote(note, () => { - dispatch((noteId: string, title: string, content: string) => { - return { - type: ADD_NOTE, - id: noteId, - title: title, - content: content - } - }) + dispatch(addNoteAction(note)) }) } } +export function updateNoteAction(note: any) { + return { + type: UPDATE_NOTE, + id: note.id, + title: note.title, + content: note.content + } +} + /** * Update existing note * @param id Note ID @@ -76,18 +86,18 @@ export function updateNote(id: string, title: string, content: string) { const note = {id: id, title: title, content: content}; return saveNote(note, () => { - dispatch((id: string, title: string, content: string) => { - return { - type: UPDATE_NOTE, - id: id, - title: title, - content: content - } - }) + dispatch(updateNoteAction(note)) }) } } +export function removeNoteAction(id: string) { + return { + type: REMOVE_NOTE, + id: id + } +} + /** * Remove note * @param id Note ID @@ -95,12 +105,7 @@ export function updateNote(id: string, title: string, content: string) { export function removeNote(id: string) { return (dispatch: any) => { return deleteNote(id, () => { - dispatch((id: string) => { - return { - type: REMOVE_NOTE, - id: id - } - }) + dispatch(removeNoteAction(id)) }) } } \ No newline at end of file diff --git a/src/components/add-note-button.tsx b/src/components/add-note-button.tsx index 1fa1e6a..f03122b 100644 --- a/src/components/add-note-button.tsx +++ b/src/components/add-note-button.tsx @@ -8,7 +8,7 @@ import { View, Button } from 'react-native'; export default class AddNoteButton extends React.Component { render() { return ( - +