<commit_before>import "homework/CalendarRow.styl";

import { h, Component } from "preact";

import moment from "moment";

import api from "api.js";
import errors from "errors.js";

import CalendarEvent from "calendar/CalendarEvent.jsx";

export default class CalendarRow extends Component {
	constructor(props) {
		super(props);

		this.state = {
			loading: true,
			error: "",
			data: {},
			timer: null,
			time: moment().valueOf()
		};
	}

	load() {
		api.get("calendar/getView", {
			start: moment().format("YYYY-MM-DD"),
			end: moment().add(1, "day").format("YYYY-MM-DD")
		}, (data) => {
			if (data.status == "ok") {
				this.setState({
					loading: false,
					data: data
				});
			} else {
				this.setState({
					loading: false,
					error: errors.getFriendlyString(data.error)
				});
			}
		});
	}

	componentDidMount() {
		this.setState({
			timer: setInterval(() => this.setState({ time: moment().valueOf() }), 1000),
		});

		this.load();
	}

	componentWillUnmount() {
		clearInterval(this.state.timer);
	}

	render(props, state) {
		if (state.loading) {
			return <div class="calendarRow">
				<div class="calendarRowTitle">Events today</div>
				<div class="calendarRowEvents">
					Loading...
				</div>
			</div>;
		}

		if (state.error) {
			return <div class="calendarRow">
				<div class="calendarRowTitle">Events today</div>
				<div class="calendarRowEvents">
					<div class="alert alert-danger">{state.error}</div>
				</div>
			</div>;
		}

		const dayData = state.data.view.days[0];
		const now = moment(state.time);

		if (dayData.events.length == 0) {
			return <div class="calendarRow">
				<div class="calendarRowTitle">Events today</div>
				<div class="noEvents">There's nothing scheduled for today.</div>
			</div>;
		}

		const events = dayData.events.sort((a, b) => moment.unix(a.start).isAfter(moment.unix(b.start)))
			.filter((event) => now.isBefore(moment.unix(event.end)))
			.map((event, i) => <CalendarEvent relativeTime key={i} type={event.type} item={event} groupIndex={0} groupLength={1} time={state.time} />);

		return <div class="calendarRow">
			<div class="calendarRowTitle">Events today</div>
			<div class="calendarRowEvents">
				{events}
				<div class="noEvents">That's it for today!</div>
			</div>
		</div>;
	}
};<commit_msg>dashboard: fix order of calendar events in chrome<commit_after>import "homework/CalendarRow.styl";

import { h, Component } from "preact";

import moment from "moment";

import api from "api.js";
import errors from "errors.js";

import CalendarEvent from "calendar/CalendarEvent.jsx";

export default class CalendarRow extends Component {
	constructor(props) {
		super(props);

		this.state = {
			loading: true,
			error: "",
			data: {},
			timer: null,
			time: moment().valueOf()
		};
	}

	load() {
		api.get("calendar/getView", {
			start: moment().format("YYYY-MM-DD"),
			end: moment().add(1, "day").format("YYYY-MM-DD")
		}, (data) => {
			if (data.status == "ok") {
				this.setState({
					loading: false,
					data: data
				});
			} else {
				this.setState({
					loading: false,
					error: errors.getFriendlyString(data.error)
				});
			}
		});
	}

	componentDidMount() {
		this.setState({
			timer: setInterval(() => this.setState({ time: moment().valueOf() }), 1000),
		});

		this.load();
	}

	componentWillUnmount() {
		clearInterval(this.state.timer);
	}

	render(props, state) {
		if (state.loading) {
			return <div class="calendarRow">
				<div class="calendarRowTitle">Events today</div>
				<div class="calendarRowEvents">
					Loading...
				</div>
			</div>;
		}

		if (state.error) {
			return <div class="calendarRow">
				<div class="calendarRowTitle">Events today</div>
				<div class="calendarRowEvents">
					<div class="alert alert-danger">{state.error}</div>
				</div>
			</div>;
		}

		const dayData = state.data.view.days[0];
		const now = moment(state.time);
		const nowTimestamp = now.unix();

		if (dayData.events.length == 0) {
			return <div class="calendarRow">
				<div class="calendarRowTitle">Events today</div>
				<div class="noEvents">There's nothing scheduled for today.</div>
			</div>;
		}

		const events = dayData.events.sort((a, b) => a.start - b.start)
			.filter((event) => nowTimestamp < event.end)
			.map((event, i) => <CalendarEvent relativeTime key={i} type={event.type} item={event} groupIndex={0} groupLength={1} time={state.time} />);

		return <div class="calendarRow">
			<div class="calendarRowTitle">Events today</div>
			<div class="calendarRowEvents">
				{events}
				<div class="noEvents">That's it for today!</div>
			</div>
		</div>;
	}
};
{'fraction_non_alphanumeric': 0.1799826313504125, 'fraction_numerical': 0.0039079461571862786, 'mean_word_length': 3.5749751737835154, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6931718', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1536, 'n_words': 328}