1- import React , { useState } from 'react'
2- import Meteor , { Mongo } from '@meteorrn/core'
3- import { Button , Text , TextInput , View , StyleSheet } from 'react-native'
4- import { inputStyles } from '../styles/inputStyles'
5-
6- const Tasks = new Mongo . Collection ( 'tasks' )
7-
8- export const MyTasks = ( props ) => {
9- const [ newTask , setNewTask ] = useState ( '' )
10- const { tasks, isLoading } = Meteor . useTracker ( ( ) => {
11- const sub = Meteor . subscribe ( 'myTasks' )
12-
13- if ( props . signedOut ) {
14- sub . stop ( )
15- return { tasks : [ ] }
16- }
17-
18- if ( ! sub . ready ( ) ) {
19- return { tasks : [ ] , isLoading : true }
20- }
21-
22- const tasks = Tasks . find ( { } , { sort : { createdAt : - 1 } } ) . fetch ( ) ;
23- return { tasks, isLoading : false }
24- } ) ;
25-
26- // add loading message
27- if ( isLoading ) {
28- return (
29- < View style = { { alignItems : 'center' } } >
30- < Text > Loading tasks...</ Text >
31- </ View >
32- )
33- }
34- // add task
35- const addTask = ( ) => {
36- Meteor . call ( 'saveTask' , { title : newTask , checked : false } , ( err , res ) => {
37- if ( err ) {
38- return console . error ( err )
39- }
40- setNewTask ( '' )
41- } )
42- }
43- const checkTask = ( { _id } ) => {
44- Meteor . call ( 'saveTask' , { _id, checked : true } , ( err , res ) => {
45- if ( err ) {
46- return console . error ( err )
47- }
48- } )
49- }
50-
51- // add task
52- const renderTaskForm = ( ) => {
53- return (
54- < View style = { { flexDirection : 'row' , alignItems : 'center' } } >
55- < TextInput
56- style = { { ...inputStyles . text , flex : 1 , flewGrow : 1 } }
57- placeholderTextColor = "#8a8a8a"
58- value = { newTask }
59- onChangeText = { setNewTask }
60- placeholder = "What do you need to remember?" />
61- < Button disabled = { newTask . length === 0 } title = "add" onPress = { addTask } />
62- </ View >
63- )
64- }
65-
66- // no tasks yet
67- if ( tasks . length === 0 ) {
68- return (
69- < View style = { { alignItems : 'center' } } >
70- < Text > No tasks yet</ Text >
71- { renderTaskForm ( ) }
72- </ View >
73- )
74- }
75-
76- const renderTasks = ( ) => tasks . map ( ( doc ) => {
77- return (
78- < View key = { doc . _id } style = { { flexDirection : 'row' , alignItems : 'center' } } >
79- < Text style = { doc . checked ? styles . checked : styles . unchecked } > { doc . title } </ Text >
80- < Button disabled = { doc . checked } title = "check" onPress = { ( ) => checkTask ( doc ) } />
81- </ View >
82- )
83- } )
84-
85- return (
86- < View style = { { alignItems : 'center' , padding : 25 } } >
87- { renderTasks ( ) }
88- { renderTaskForm ( ) }
89- </ View >
90- )
91- }
92-
93- const styles = StyleSheet . create ( {
94- checked : {
95- textDecorationLine : 'line-through' ,
96- textDecorationStyle : 'solid' ,
97- flex : 1 ,
98- flexGrow : 1
99- } ,
100- unchecked : {
101- fontWeight : 'bold' ,
102- flex : 1 ,
103- flexGrow : 1
104- }
105- } )
1+ import React from 'react'
2+ import { Text } from 'react-native'
3+
4+ /**
5+ * Here you can implement the logic to subscribe to your tasks and CRUD them.
6+ * See: https://github.com/meteorrn/sample
7+ * @param props
8+ * @returns {JSX.Element }
9+ * @constructor
10+ */
11+ export const MyTasks = ( ) => ( < Text > My Tasks not yet implemented</ Text > )
0 commit comments