Skip to content
This repository was archived by the owner on Feb 21, 2020. It is now read-only.

Commit d350468

Browse files
authored
Merge pull request #170 from BoostIO/show-note-update
Show note update date on note list
2 parents a9da87e + 6291636 commit d350468

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

app/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ export default class App extends Component {
252252
fileName: fileName,
253253
content: content === '' ? 'Tap here and write something!' : content.split(/\r\n|\r|\n/)[0],
254254
createdAt: filteredSettingFile.createdAt,
255-
isStarred: filteredSettingFile.isStarred
255+
isStarred: filteredSettingFile.isStarred,
256+
updatedAt: filteredSettingFile.updatedAt,
256257
})
257258
}
258259
fileList.sort((a, b) => {
@@ -301,7 +302,6 @@ export default class App extends Component {
301302
'updatedAt': date
302303
}
303304
contentObject.note.push(thisNote)
304-
console.table(contentObject.note)
305305
fs.writeFile(`${dirs.DocumentDir}/Boostnote/boostnote.json`, JSON.stringify(contentObject), 'utf8')
306306
.catch(err => console.log(err))
307307
AwsMobileAnalyticsConfig.recordDynamicCustomEvent('CREATE_NOTE')

app/components/NoteList/NoteListItem.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const styles = {
6565
flexDirection: 'row',
6666
justifyContent: 'flex-start',
6767
alignItems: 'center',
68-
flex: 2
68+
flex: 3
6969
},
7070
noteItemSectionRight: {
7171
flex: 1,
@@ -98,16 +98,16 @@ class NoteListItem extends Component {
9898

9999
render () {
100100
const { note } = this.props || {}
101-
const { content, createdAt, isStarred } = note || {}
101+
const { content, createdAt, isStarred, updatedAt } = note || {}
102102
return (
103103
<TouchableOpacity
104104
style={styles.noteList}
105105
onPress={this.onNotePress}>
106106
<View style={styles.noteItemSectionLeft}>
107-
<Text style={content !== 'Tap here and write something!' ? styles.noteListText : styles.noteListTextNone}>{removeMd(content)}</Text>
107+
<Text numberOfLines={2} ellipsizeMode="tail" style={content !== 'Tap here and write something!' ? styles.noteListText : styles.noteListTextNone}>{removeMd(content)}</Text>
108108
</View>
109109
<View style={styles.noteItemSectionRight}>
110-
<Text style={styles.noteListDate}>{moment(createdAt).format('MMM D')}</Text>
110+
<Text style={styles.noteListDate}>{moment(updatedAt).format('MMM D') + '\n' + moment(createdAt).format('MMM D')}</Text>
111111
<TouchableOpacity onPress={this.onStarPress}>
112112
<Icon name={isStarred ? 'md-star' : 'md-star-outline'} style={styles.noteStarIcon} />
113113
</TouchableOpacity>

app/views/note/NoteModal.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,32 @@ export default class NoteModal extends React.Component {
5252
})
5353
}
5454

55-
onChangeText (text) {
55+
async onChangeText(text) {
56+
// set note state
5657
this.setState({
5758
text: text
5859
})
60+
61+
// save to file
5962
const dirs = RNFetchBlob.fs.dirs
6063
fs.writeFile(`${dirs.DocumentDir}/Boostnote/${this.state.fileName}`, text, 'utf8')
64+
65+
// update note list data
66+
const settingJsonFile = await fs.readFile(`${dirs.DocumentDir}/Boostnote/boostnote.json`, 'utf8')
67+
const parsedSetting = JSON.parse(settingJsonFile);
68+
let filteredSettingFile = parsedSetting.note.filter(setting => {
69+
return setting.name === this.state.fileName
70+
})[0]
71+
filteredSettingFile.updatedAt = new Date()
72+
let newJsonFile = parsedSetting.note
73+
.filter(setting => {
74+
return setting.name !== this.state.fileName
75+
})
76+
newJsonFile.push(filteredSettingFile)
77+
parsedSetting.note = newJsonFile
78+
79+
fs.writeFile(`${dirs.DocumentDir}/Boostnote/boostnote.json`, JSON.stringify(parsedSetting), 'utf8')
80+
.catch(err => console.log(err))
6181
}
6282

6383
componentWillMount () {

0 commit comments

Comments
 (0)