Skip to content

Commit

Permalink
Create action methods from previous inline functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Avci committed Mar 6, 2019
1 parent 2ebacff commit 00eae35
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
51 changes: 28 additions & 23 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -76,31 +86,26 @@ 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
*/
export function removeNote(id: string) {
return (dispatch: any) => {
return deleteNote(id, () => {
dispatch((id: string) => {
return {
type: REMOVE_NOTE,
id: id
}
})
dispatch(removeNoteAction(id))
})
}
}
2 changes: 1 addition & 1 deletion src/components/add-note-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { View, Button } from 'react-native';
export default class AddNoteButton extends React.Component<any> {
render() {
return (
<View style={{marginBottom: 36}}>
<View style = {{ marginBottom: 36 }}>
<Button
onPress={() => this.props.navigation.navigate('NewNote')}
title="Add Note"
Expand Down
4 changes: 0 additions & 4 deletions src/screens/home-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import { NotesList } from "../containers"
import { fetchNotes } from "../actions"

class HomeScreen extends React.Component<any> {
state = {
isLoading: this.props.isLoading,
}

static navigationOptions = {
title: 'Notes',
};
Expand Down

0 comments on commit 00eae35

Please sign in to comment.