Skip to content

Commit

Permalink
reminder method
Browse files Browse the repository at this point in the history
  • Loading branch information
rainyuxuan committed Nov 8, 2020
1 parent 4fe9fa5 commit cef0709
Show file tree
Hide file tree
Showing 3 changed files with 273 additions and 116 deletions.
145 changes: 124 additions & 21 deletions Flourish/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,145 @@ function loadMyPlants(test) {
if (test){
return [
{
'id': '0',
'name': 'The Green Ball',
'task': 'Watering',
'freq': 7,
"id": "0",
"img": "https://i1.kknews.cc/SIG=52b418/26r5000002r82qro63ro.jpg",
'date': new Date('October 29, 2020 10:03:00'),
"name": "Red",
"binomial": "Echeveria Apus",
"intro": "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Eius ipsum eveniet laboriosam dolore perspiciatis, numquam iusto provident nobis, commodi voluptatem repellat nemo, quae voluptate facilis fuga labore in? Debitis, minus!",
"maintain": [
{
"key": 0,
"title": "SUNSHINE",
"spec": "Full daylight",
},
{
"key": 1,
"title": "WATERING",
"spec": "1 per week",
},
],
"reminder": [
{
"key": 0,
"name": "Red",
"task": "WATERING",
"freq": "7",
"date": new Date('May 4, 2020 17:29:03'),
},
{
"key": 1,
"name": "Red",
"task": "FERTILIZING",
"date": new Date('May 4, 2020 17:29:03'),
"freq": "7",
},
],
},
{
'id': '1',
'name': 'The Red Ball',
'task': 'Watering',
'freq': 7,
"id": "1",
"img": "https://www.zhifure.com/upload/images/2018/3/27164120681.jpg",
'date': new Date('May 4, 2020 17:29:03'),
"name": "The Succulents",
"binomial": "Echeveria Apus",
"intro": "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Eius ipsum eveniet laboriosam dolore perspiciatis, numquam iusto provident nobis, commodi voluptatem repellat nemo, quae voluptate facilis fuga labore in? Debitis, minus!",
"maintain": [
{
"key": 0,
"title": "SUNSHINE",
"spec": "Full daylight",
},
{
"key": 1,
"title": "WATERING",
"spec": "1 per week",
},
],
"reminder": [
{
"key": 0,
"name": "The Succulents",
"task": "WATERING",
"freq": "14",
"date": new Date(Date.now()),
},
{
"key": 1,
"name": "The Succulents",
"task": "FERTILIZING",
"date": new Date(Date.now()),
"freq": "14",
},
],
},
{
'id': '2',
'name': 'The Blue Ball',
'task': 'Watering',
'freq': 7,
"id": "2",
"img": "https://duorou.zw3e.com/uploads/allimg/180828/3-1PRQ12410227.jpg",
'date': new Date(Date.now()),
"name": "Greens",
"binomial": "Echeveria Apus",
"intro": "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Eius ipsum eveniet laboriosam dolore perspiciatis, numquam iusto provident nobis, commodi voluptatem repellat nemo, quae voluptate facilis fuga labore in? Debitis, minus!",
"maintain": [
{
"key": 0,
"title": "SUNSHINE",
"spec": "Full daylight",
},
{
"key": 1,
"title": "WATERING",
"spec": "1 per week",
},
],
"reminder": [
{
"key": 0,
"name": "Greens",
"task": "WATERING",
"freq": "7",
"date": new Date('November 11, 2018 22:44:53'),
},
{
"key": 1,
"name": "Greens",
"task": "FERTILIZING",
"date": new Date('November 11, 2018 22:44:53'),
"freq": "7",
},
],
},
{
'id': '3',
'name': 'The Orange Ball',
'task': 'Watering',
'freq': 7,
"id": "3",
"img": "https://i.epochtimes.com/assets/uploads/2020/05/shutterstock_1714301299-600x400.jpg",
'date': new Date('November 3, 2018 22:44:53'),
"name": "Yeah",
"binomial": "Echeveria Apus",
"intro": "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Eius ipsum eveniet laboriosam dolore perspiciatis, numquam iusto provident nobis, commodi voluptatem repellat nemo, quae voluptate facilis fuga labore in? Debitis, minus!",
"maintain": [
{
"key": 0,
"title": "SUNSHINE",
"spec": "Full daylight",
},
{
"key": 1,
"title": "WATERING",
"spec": "1 per week",
},
],
"reminder": [
{
"key": 0,
"name": "Yeah",
"task": "WATERING",
"freq": "7",
"date": new Date('October 29, 2020 10:03:00'),
},
{
"key": 1,
"name": "Yeah",
"task": "FERTILIZING",
"date": new Date('October 30, 2020 10:03:00'),
"freq": "7",
},
],
},

]
} else {
const access = new StorageAccess({})
Expand Down
142 changes: 88 additions & 54 deletions Flourish/Tabs/FlourishingTabScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,59 @@ import { SafeAreaView, StatusBar, StyleSheet, Text, View, ScrollView, SectionLis
import Todo from '../Components/Flourishing/Todo';


export default class FlourishingTabScreen extends React.Component{
export default class FlourishingTabScreen extends React.Component {
componentDidMount() {
this.setState({
plants: this.props.plants
plants: this.props.plants,

})
this.getAllReminders();
}

state = {
plants: [],
reminders: []
reminders: [],
todayReminders: [],
weekReminders: [],
}

getAllReminders = () => {
let plants = this.state.plants;
let todayReminders = [];
let weekReminders = [];
let dayMili = 24 * 60 * 60 * 1000
let today = new Date(Date.now());
let week = new Date(today.getTime() + 7 * dayMili);

for (let i = 0; i < plants.length; i++) {
for (let j = 0; j < plants[i].reminders.length; j++) {
let r = plants[i].reminders[j];
if (r.date.getTime() < today.getTime() + 1 * dayMili && r.date.getTime() > today.getTime() - dayMili) {
todayReminders.push(r);
} else if (r.date.getTime() < week.getTime()) {
weekReminders.push(r);
}
}
}

this.setState({ todayReminders: todayReminders, weekReminders: weekReminders });
this.setState({
reminders: [{
title: "Today",
data: todayReminders,
},
{
title: "This Week",
data: weekReminders,
}]
});
}

renderItem = ({ item }) => {

renderItem = ({ item }) => {
return (
<Todo name={item.name} task={item.task} freq={item.freq} date={item.date} checked={item.checked}/>
<Todo name={item.name} task={item.task} freq={item.freq} date={item.date} checked={false} />
);

}

render() {
Expand Down Expand Up @@ -72,51 +106,51 @@ const styles = StyleSheet.create({
});


const TODAY_DATA = [
{
'id': '0',
'name': 'The Green Ball',
'task': 'Watering',
'freq': 7,
'date': new Date("October 13, 2014 11:13:00"),
'checked': false,
},
{
'id': '1',
'name': 'The Red Ball',
'task': 'Watering',
'freq': 7,
'date': new Date("October 29, 2020 10:03:00"),
'checked': true,
},
{
'id': '2',
'name': 'The Blue Ball',
'task': 'Watering',
'freq': 30,
'date': new Date("May 29, 2019 22:03:47"),
'checked': true,
},
{
'id': '3',
'name': 'The Orange Ball',
'task': 'Watering',
'freq': 7,
'date': new Date("October 29, 2020 10:03:00"),
'checked': true,
},
]


const WEEK_DATA = TODAY_DATA;

const DATA = [
{
title: "Today",
data: TODAY_DATA,
},
{
title: "This Week",
data: WEEK_DATA,
}
]
// const TODAY_DATA = [
// {
// 'id': '0',
// 'name': 'The Green Ball',
// 'task': 'Watering',
// 'freq': 7,
// 'date': new Date("October 13, 2014 11:13:00"),
// 'checked': false,
// },
// {
// 'id': '1',
// 'name': 'The Red Ball',
// 'task': 'Watering',
// 'freq': 7,
// 'date': new Date("October 29, 2020 10:03:00"),
// 'checked': true,
// },
// {
// 'id': '2',
// 'name': 'The Blue Ball',
// 'task': 'Watering',
// 'freq': 30,
// 'date': new Date("May 29, 2019 22:03:47"),
// 'checked': true,
// },
// {
// 'id': '3',
// 'name': 'The Orange Ball',
// 'task': 'Watering',
// 'freq': 7,
// 'date': new Date("October 29, 2020 10:03:00"),
// 'checked': true,
// },
// ]


// const WEEK_DATA = TODAY_DATA;

// const DATA = [
// {
// title: "Today",
// data: TODAY_DATA,
// },
// {
// title: "This Week",
// data: WEEK_DATA,
// }
// ]
Loading

0 comments on commit cef0709

Please sign in to comment.