@@ -16,30 +16,37 @@ import {
1616import NoteWidget from './Widgets/NoteWidget' ;
1717import Colors from './Resources/Colors' ;
1818
19- const window = Dimensions . get ( 'window' ) ;
20- const screen = Dimensions . get ( 'screen' ) ;
21-
2219const noteWidgetWidth = 300 ;
2320
24- class NotesMainPanel extends React . Component {
25- constructor ( props ) {
21+ function calculateColumnWidth ( ) {
22+ return Math . floor ( Dimensions . get ( 'window' ) . width / noteWidgetWidth ) ;
23+ }
24+
25+ interface Props { }
26+
27+ interface INote {
28+ key : number ;
29+ title : string ;
30+ shortMessage : string ;
31+ }
32+
33+ interface State {
34+ notes : Array < INote > ;
35+ columns : number ;
36+ }
37+
38+ class NotesMainPanel extends React . Component < Props , State > {
39+ constructor ( props : Props ) {
2640 super ( props ) ;
2741 this . state = {
2842 notes : [ ] ,
29- dimensions : { window, screen} ,
30- columns : this . calculateColumnWidth ( window ) ,
31- isMounted : false ,
43+ columns : calculateColumnWidth ( ) ,
3244 } ;
3345 }
3446
35- calculateColumnWidth = ( ) => {
36- return Math . floor ( Dimensions . get ( 'window' ) . width / noteWidgetWidth ) ;
37- } ;
38-
39- onChange = ( { window, screen} ) => {
47+ onChange = ( ) => {
4048 this . setState ( {
41- dimensions : { window, screen} ,
42- columns : this . calculateColumnWidth ( ) ,
49+ columns : calculateColumnWidth ( ) ,
4350 } ) ;
4451 } ;
4552
@@ -52,25 +59,16 @@ class NotesMainPanel extends React.Component {
5259 Dimensions . removeEventListener ( 'change' , this . onChange ) ;
5360 }
5461
55- createNotesKeys = async ( notesIDs ) => {
62+ createNotesKeys = async ( notesIDs : Array < INote > ) => {
5663 this . setState ( { notes : notesIDs } ) ;
5764 } ;
5865
5966 getDataFromDatabase = async ( ) => {
6067 await NativeModules . Database . getAllNotesIDs ( )
61- . then ( ( result ) => this . createNotesKeys ( result ) )
62- . catch ( ( error ) => Alert . alert ( 'ERROR!' , `Result: ${ error } ` ) ) ;
63- } ;
64-
65- renderNote = ( notes ) => {
66- return (
67- < NoteWidget
68- width = { noteWidgetWidth }
69- ID = { notes . item . key }
70- title = { notes . item . title }
71- shortMessage = { notes . item . shortMessage }
72- />
73- ) ;
68+ . then ( ( result : Array < INote > ) => this . createNotesKeys ( result ) )
69+ . catch ( ( error : Error ) =>
70+ Alert . alert ( 'ERROR!' , `Result: ${ error . message } ` ) ,
71+ ) ;
7472 } ;
7573
7674 renderWelcomePage = ( ) => {
@@ -89,11 +87,18 @@ class NotesMainPanel extends React.Component {
8987 renderNotesPage = ( ) => {
9088 return (
9189 < View style = { styles . mainContainer } >
92- < FlatList
90+ < FlatList < INote >
9391 key = { this . state . columns }
9492 numColumns = { this . state . columns }
9593 data = { this . state . notes }
96- renderItem = { this . renderNote }
94+ renderItem = { ( { item} ) => (
95+ < NoteWidget
96+ width = { noteWidgetWidth }
97+ id = { item . key }
98+ title = { item . title }
99+ shortMessage = { item . shortMessage }
100+ />
101+ ) }
97102 />
98103 </ View >
99104 ) ;
0 commit comments