<commit_before>import * as React from 'react';
import { Redirect, RouteComponentProps } from 'react-router-dom';
import Snackbar from 'material-ui/Snackbar';

interface Room {
    id: string;
    name: string;
    lightIds: string[];
    state: {};
}

class LightsPageState {
    rooms: Room[];
    showSnackbar: boolean;
    snackbarMessage: string;
}

export default class LightsPage extends React.Component<RouteComponentProps<any>, LightsPageState> {
    constructor(props: any) {
        super(props);

        this.state = {
            rooms: [],
            showSnackbar: false,
            snackbarMessage: ''
        };

        this.handleRequestClose = this.handleRequestClose.bind(this);
    }

    async componentDidMount() {
        try {
            const response = await fetch(`/api/rooms`, {
                headers: {
                    'Authorization': `Bearer ${sessionStorage.getItem('userToken')}`
                }
            });
            const resBody = await response.json();

            this.setState({
                rooms: resBody
            });
        }
        catch(e) {
            this.setState({
                showSnackbar: true,
                snackbarMessage: 'There was an error getting the rooms'
            });
        }
    }

    handleRequestClose() {
        this.setState({
            showSnackbar: false,
            snackbarMessage: ''
        });
    }

    render() {
        if (!sessionStorage.getItem('userToken')) {
            return (<Redirect to="/" />);
        }

        return (
            <div style={{ margin: '16px' }}>
                <span style={{ fontFamily: 'Roboto', fontSize: '20px' }}>
                    No rooms to display
                </span>
                <Snackbar
                    open={this.state.showSnackbar}
                    message={this.state.snackbarMessage}
                    autoHideDuration={4000}
                    onRequestClose={this.handleRequestClose} />
            </div>
        );
    }
}<commit_msg>get the rooms and actually display them<commit_after>import * as React from 'react';
import { Redirect, RouteComponentProps } from 'react-router-dom';
import Snackbar from 'material-ui/Snackbar';

interface Room {
    id: string;
    name: string;
    lightIds: string[];
    state: {};
}

class LightsPageState {
    rooms: Room[];
    showSnackbar: boolean;
    snackbarMessage: string;
}

export default class LightsPage extends React.Component<RouteComponentProps<any>, LightsPageState> {
    constructor(props: any) {
        super(props);

        this.state = {
            rooms: [],
            showSnackbar: false,
            snackbarMessage: ''
        };

        this.handleRequestClose = this.handleRequestClose.bind(this);
    }

    async componentDidMount() {
        try {
            const response = await fetch(`/api/rooms`, {
                headers: {
                    'Authorization': `Bearer ${sessionStorage.getItem('userToken')}`
                }
            });
            const resBody = await response.json();

            this.setState({
                rooms: resBody
            });
        }
        catch(e) {
            this.setState({
                showSnackbar: true,
                snackbarMessage: 'There was an error getting the rooms'
            });
        }
    }

    handleRequestClose() {
        this.setState({
            showSnackbar: false,
            snackbarMessage: ''
        });
    }

    render() {
        let roomsToDisplay;

        if (!sessionStorage.getItem('userToken')) {
            return (<Redirect to="/" />);
        }

        if (this.state.rooms.length === 0) {
            roomsToDisplay = (
                <span style={{ fontFamily: 'Roboto', fontSize: '20px' }}>
                    No rooms to display
                </span>
            );
        }
        else {
            roomsToDisplay = this.state.rooms.map(r => (
                <div key={r.id} style={{ fontFamily: 'Roboto', fontSize: '20px' }}>
                    {r.name}
                </div>
            ));
        }

        return (
            <div style={{ margin: '16px' }}>
                {roomsToDisplay}
                <Snackbar
                    open={this.state.showSnackbar}
                    message={this.state.snackbarMessage}
                    autoHideDuration={4000}
                    onRequestClose={this.handleRequestClose} />
            </div>
        );
    }
}
{'fraction_non_alphanumeric': 0.11607142857142858, 'fraction_numerical': 0.004241071428571428, 'mean_word_length': 1.5005580357142858, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, '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': '2825753', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1175, 'n_words': 247}