question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to load items in the agenda

See original GitHub issue

How can I load items in order to get a working demo for the agenda as seen in the agenda gif in the readme. Here is my code, most of which is from the Agenda.js file:

import React, { Component } from 'react';
import {
  Alert,
  Button,
  Platform,
  Text,
  StyleSheet,
  ScrollView,
  View
} from 'react-native';

import {Calendar, CalendarList, Agenda} from 'react-native-calendars';

export default class App extends Component {

constructor(props) {
    super(props);
    this.state = {
      items: {}
    };
  }

  render() {
    return (
      <Agenda

      items={
    {'2017-05-22': [{text: 'item 1 - any js object'}],
     '2017-05-23': [{text: 'item 2 - any js object'}],
     '2017-05-24': [],
     '2017-05-25': [{text: 'item 3 - any js object'},{text: 'any js object'}],
    }}

        items={this.state.items}
        loadItemsForMonth={this.loadItems.bind(this)}
        selected={'2017-05-16'}
        renderItem={this.renderItem.bind(this)}
        renderEmptyDate={this.renderEmptyDate.bind(this)}
        rowHasChanged={this.rowHasChanged.bind(this)}
      />
    );
  }

  loadItems(day) {
    setTimeout(() => {
      for (let i = -15; i < 85; i++) {
        const time = day.timestamp + i * 24 * 60 * 60 * 1000;
        const strTime = this.timeToString(time);
        if (!this.state.items[strTime]) {
          this.state.items[strTime] = [];
          const numItems = Math.floor(Math.random() * 5);
          for (let j = 0; j < numItems; j++) {
            this.state.items[strTime].push({
              name: 'Item for ' + strTime,
              height: Math.max(50, Math.floor(Math.random() * 150))
            });
          }
        }
      }
      //console.log(this.state.items);
      const newItems = {};
      Object.keys(this.state.items).forEach(key => {newItems[key] = this.state.items[key];});
      this.setState({
        items: newItems
      });
    }, 1000);
    // console.log(`Load Items for ${day.year}-${day.month}`);
  }

  renderItem(item) {
    return (
      <View style={[styles.item, {height: item.height}]}><Text>{item.name}</Text></View>
    );
  }

  renderEmptyDate() {
    return (
      <View style={styles.emptyDate}><Text>This is empty date!</Text></View>
    );
  }

  rowHasChanged(r1, r2) {
    return r1.name !== r2.name;
  }

  timeToString(time) {
    const date = new Date(time);
    return date.toISOString().split('T')[0];
  }
}

const styles = StyleSheet.create({
  item: {
    backgroundColor: 'white',
    flex: 1,
    borderRadius: 5,
    padding: 10,
    marginRight: 10,
    marginTop: 17
  },
  emptyDate: {
    height: 15,
    flex:1,
    paddingTop: 30
  }
});

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

16reactions
tautvilascommented, Mar 1, 2018
15reactions
DavidAPearscommented, Jan 6, 2020

Does anyone have an example of this which uses actual data for ‘items’ rather than the randomly generated items in the example listed by @tautvilas, this seems overly confusing.

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding a New Agenda Item Before or During the Meeting
Click Agenda Item at the top of the screen, or right-click an existing agenda item in the left Agenda panel and select Add...
Read more >
Add agenda items to your meeting
You can add agenda items to your meeting on the Meetings & Offline tab. First, click the Agenda tab under your meeting: Next...
Read more >
Quick tips – Working with Agenda Items
To do so, click on the 'Inactive' agenda item list, check any item(s) and or sub-item(s) you want to reactivate and click the...
Read more >
Help: Adding Agenda Items to Outlook Meetings yoyomeeting ...
You add the agenda item to your agenda by clicking “Save agenda item”. This copies all information to the text section of your...
Read more >
How to Write a Meeting Agenda: 5 Items You Should Always ...
5. Define the meeting goal. · 4. Outline a list of meeting agenda topics for discussion · 3. Identify the list of required...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found