Created
September 30, 2018 16:57
-
-
Save alvinmatias69/23561f60b8b9fbc4025fa802422c73b6 to your computer and use it in GitHub Desktop.
Simple React Chat UI snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
processData(data) { | |
const conversations = data.map(item => ({ | |
...item, | |
date: parseDate(item.date), | |
selected: false, | |
})); | |
this.setState({ conversations }); | |
} | |
select(id) { | |
const { conversations, selecting } = this.state; | |
if (selecting) { | |
this.setState({ | |
conversations: conversations.map(item => ({ | |
...item, | |
selected: item.id === id ? !item.selected : item.selected, | |
})) | |
}) | |
} | |
} | |
removeSelected() { | |
const { conversations } = this.state; | |
this.setState({ | |
selecting: false, | |
conversations: conversations.map(item => ({ | |
...item, | |
selected: false, | |
})) | |
}) | |
} | |
deleteChat() { | |
const { conversations } = this.state; | |
const id = conversations.reduce((acc, cur) => { | |
if (cur.selected) { | |
acc.push(cur.id); | |
} | |
return acc; | |
}, []); | |
// call deleting endpoint using id | |
console.log({ id }); | |
this.deleteSelected(); | |
} | |
deleteSelected() { | |
const { conversations } = this.state; | |
this.setState({ | |
selecting: false, | |
conversations: conversations.filter(item => !item.selected), | |
}); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment