Skip to content
Snippets Groups Projects
Import.js 4.94 KiB
Newer Older
theraj's avatar
theraj committed
import React, { Component } from 'react';
tspuller's avatar
bla
tspuller committed
import { Row, Col } from 'antd';

import Dropzone from '@imd/components/uielements/dropzone';
import { notification } from '@imd/components';
import PageHeader from '@imd/components/utility/pageHeader';
import Box from '@imd/components/utility/box';
import LayoutWrapper from '@imd/components/utility/layoutWrapper';
import ContentHolder from '@imd/components/utility/contentHolder';
tspuller's avatar
tspuller committed
import DropzoneWrapper from './Import.styles';
tspuller's avatar
bla
tspuller committed

import basicStyle from '@imd/assets/styles/constants';
import FrappeChart from 'frappe-charts/dist/frappe-charts.min.esm';
import * as configs from './config';
import 'frappe-charts/dist/frappe-charts.min.css';
theraj's avatar
theraj committed
import Tabs, { TabPane } from '@imd/components/uielements/tabs';
tspuller's avatar
bla
tspuller committed
import IsoWidgetsWrapper from '@imd/containers/Widgets/WidgetsWrapper';

import CardWidget from '@imd/containers/Widgets/Card/CardWidget';
import IntlMessages from '@imd/components/utility/intlMessages';
import TotalSongsByDayLine from './Components/TotalSongsByDayLine/TotalSongsByDayLine';
theraj's avatar
theraj committed
import UserData from './Data/StreamingHistory0.json';

function callback(key) {}
tspuller's avatar
bla
tspuller committed

export default class extends Component {

  componentDidMount() {
    new FrappeChart(configs.impressionsLineChart);
  }

  render() {

    let totalSongs = UserData.length;

tspuller's avatar
bla
tspuller committed
    const CARD_WIDGET = [
      {
        icon: 'ion-music-note',
        iconcolor: '#1db954',
        number: totalSongs.toString(),
        text: 'Total Listens',
      },
    ];
tspuller's avatar
bla
tspuller committed

    //##########
    //Dropzone
    //##########
    const componentConfig = {
      iconFiletypes: ['.json'],
      method: true,
      showFiletypeIcon: false,
      uploadMultiple: false,
      maxFilesize: 2, // MB
      maxFiles: 1,
      dictRemoveFile: 'Delete',
      dictCancelUploadConfirmation: 'Are you sure to cancel upload?',
      postUrl: '/upload',
    };
    const djsConfig = {
      acceptedFiles: '.json',
      params: {
        account: "tinder"
      }
    };
    const eventHandlers = {
      addedfile: file => notification('success', `${file.name} added`),
      success: file =>
        notification('success', `${file.name} successfully uploaded`),
tspuller's avatar
tspuller committed
      error: error => notification('error', 'Server is not set in the demo')
tspuller's avatar
bla
tspuller committed
    };

    const { rowStyle, colStyle, gutter } = basicStyle;

    return (
      <LayoutWrapper>
tspuller's avatar
tspuller committed
        <PageHeader>Import</PageHeader>
tspuller's avatar
tspuller committed
        <Row style={rowStyle} gutter={gutter} justify="start">
            <Col span={24} style={colStyle}>
tspuller's avatar
tspuller committed
            <Box>
              <u>How To Download Your Spotify Data:</u> <br></br>
              1. Log in to <a href="https://www.spotify.com/us/">spotify.com</a> <br></br>
              2. Click <b>Log In</b> and enter your credentials <br></br>
              3. Select <b>Privacy Settings</b> from the left-hand navigation<br></br>
              4. Scroll down to <b>Download Your Data</b> and select <b>Request</b><br></br>
              5. Go to your email to confirm your request<br></br>
              6. Upload your data in the dropbox below<br></br>
tspuller's avatar
tspuller committed
            </Box>
            </Col>
        </Row>
tspuller's avatar
bla
tspuller committed
        <Box>
          <ContentHolder>
            <DropzoneWrapper>
              <Dropzone
                config={componentConfig}
                eventHandlers={eventHandlers}
                djsConfig={djsConfig}
              />
            </DropzoneWrapper>
          </ContentHolder>
        </Box>
theraj's avatar
theraj committed

        <PageHeader>Data & Analytics</PageHeader>
        <Box>
          <Tabs defaultActiveKey="1" onChange={callback}>
            <TabPane tab="Raw Data" key="1">
theraj's avatar
theraj committed
              {UserData.map((song, idx) => (
                <Col lg={6} md={12} sm={12} xs={24} style={colStyle}>
                  <Box>
                    <h1>{song.trackName}</h1>
                    <div>Artist: {song.artistName}</div>
                    <div>{song.endTime}</div>
                  </Box>
                </Col>
              ))}
theraj's avatar
theraj committed
            </TabPane>
            <TabPane tab="Graphs" key="2">
            <Row style={rowStyle} gutter={0} justify="start">
              <Col lg={6} md={12} sm={12} xs={24} style={colStyle}>
                {CARD_WIDGET.map((widget, idx) => (
                  <IsoWidgetsWrapper key={idx} gutterBottom={20}>
                    {/* Card Widget */}
                    <CardWidget
                      icon={widget.icon}
                      iconcolor={widget.iconcolor}
                      number={widget.number}
                      text={widget.text}
                    />
                  </IsoWidgetsWrapper>
                ))}
              </Col>
              <Col lg={18} md={12} sm={12} xs={24} style={colStyle}>
              <IsoWidgetsWrapper>
                  <Box title="Total Songs By Day">
                    <ContentHolder>
                      <TotalSongsByDayLine />
                    </ContentHolder>
                  </Box>
                </IsoWidgetsWrapper>
              </Col>
            </Row>
theraj's avatar
theraj committed
            </TabPane>
          </Tabs>
        </Box>
tspuller's avatar
bla
tspuller committed
      </LayoutWrapper>
    );
  };
}