<commit_before>import _ from 'lodash'
import React, {PropTypes} from 'react'
import Delir from 'delir-core'
const {Helper: DelirHelper} = Delir

import EditorStateActions from '../actions/editor-state-actions'
import ProjectModifyActions from '../actions/project-modify-actions'

import AppStore from '../stores/app-store'
import EditorStateStore from '../stores/editor-state-store'
import ProjectModifyStore from '../stores/project-modify-store'

import Pane from './components/pane'
import LabelInput from './components/label-input'
import SelectList from './components/select-list'
import {Table, TableHeader, TableBodySelectList, Row, Col} from './components/table'
import {ContextMenu, MenuItem} from './electron/context-menu'
import ModalWindow from './electron/modal-window'

import NewCompositionWindow from './modal-windows/new-composition-window'
import SettingCompositionWindow from './modal-windows/setting-composition-window'

export default class AssetsView extends React.Component
{
    constructor()
    {
        super()

        this.state = {
            app: AppStore.getState(),
            project: EditorStateStore.getState(),
            newCompositionWindowOpened: false,
            settingCompositionWindowOpened: false,
            settingCompositionQuery: null,
            selectedItem: null,
        }

        AppStore.addListener(() => {
            this.setState({app: AppStore.getState()})
        })

        EditorStateStore.addListener(() => {
            this.setState({project: EditorStateStore.getState()})
        })

        ProjectModifyStore.addListener(() => {
            this.forceUpdate()
        })
    }

    addAsset = e => {
        console.log(e.dataTransfer, e.dataTransfer.files[0], e.dataTransfer.items[0]);

        _.each(e.dataTransfer.files, (file, idx) => {
            if (!e.dataTransfer.items[idx].webkitGetAsEntry().isFile) return

            ProjectModifyActions.addAsset({
                name: file.name,
                mimeType: file.type,
                path: file.path,
            })
        })
    }

    changeComposition = (compId, e) =>
    {
        EditorStateActions.changeActiveComposition(compId)
    }

    modifyCompName = (compId, newName) =>
    {
        ProjectModifyActions.modifyComposition(compId, {name: newName})
    }

    openCompositionSettingWindow = compId =>
    {
        const targetComposition = DelirHelper.findCompositionById(this.state.project.project, compId)

        this.setState({
            settingCompositionQuery: {
                id: targetComposition.id,
                name: targetComposition.name,
                width: targetComposition.width,
                height: targetComposition.height,
                framerate: targetComposition.framerate,
                durationFrame: targetComposition.durationFrame,
                samplingRate: targetComposition.samplingRate,
                audioChannels: targetComposition.audioChannels,
            },
            settingCompositionWindowOpened: true,
        })
    }

    settingComoisition = (req: {
        id:string,
        name: string,
        width: string,
        height: string,
        framerate: string,
        durationSeconds: string
    }) => {
        this.setState({
            settingCompositionQuery: null,
            settingCompositionWindowOpened: false,
        })

        ProjectModifyActions.modifyComposition(req.id, req)
    }

    makeNewComposition = (req: {name: string, width: string, height: string, framerate: string, durationSeconds: string}) =>
    {
        if (req == null) return

        // `newCompositionWindowOpened` must be `false` before create Action.
        // this state is not synced to real window show/hide state.
        // if other state changing fired early to set `false`,
        // component updated and open modal window once again by current state.
        this.setState({newCompositionWindowOpened: false})

        ProjectModifyActions.createComposition({
            name: req.name,
            width: req.width | 0,
            height: req.height | 0,
            framerate: req.framerate | 0,
            durationFrames: (req.framerate | 0) * parseInt(req.durationSeconds, 10)
        })
    }

    render()
    {
        const {app, project: {project}} = this.state
        const assets = project ? Array.from(project.assets.values()) : []
        const compositions = project ? Array.from(project.compositions.values()) : []

        return (
            <Pane className='view-assets' allowFocus>
                <NewCompositionWindow
                    show={this.state.newCompositionWindowOpened}
                    width={400}
                    height={350}
                    onHide={this.props.makeNewComposition}
                    onResponse={this.props.makeNewComposition}
                /><commit_msg>fix missing props assginment<commit_after>import _ from 'lodash'
import React, {PropTypes} from 'react'
import Delir from 'delir-core'
const {Helper: DelirHelper} = Delir

import EditorStateActions from '../actions/editor-state-actions'
import ProjectModifyActions from '../actions/project-modify-actions'

import AppStore from '../stores/app-store'
import EditorStateStore from '../stores/editor-state-store'
import ProjectModifyStore from '../stores/project-modify-store'

import Pane from './components/pane'
import LabelInput from './components/label-input'
import SelectList from './components/select-list'
import {Table, TableHeader, TableBodySelectList, Row, Col} from './components/table'
import {ContextMenu, MenuItem} from './electron/context-menu'
import ModalWindow from './electron/modal-window'

import NewCompositionWindow from './modal-windows/new-composition-window'
import SettingCompositionWindow from './modal-windows/setting-composition-window'

export default class AssetsView extends React.Component
{
    constructor()
    {
        super()

        this.state = {
            app: AppStore.getState(),
            project: EditorStateStore.getState(),
            newCompositionWindowOpened: false,
            settingCompositionWindowOpened: false,
            settingCompositionQuery: null,
            selectedItem: null,
        }

        AppStore.addListener(() => {
            this.setState({app: AppStore.getState()})
        })

        EditorStateStore.addListener(() => {
            this.setState({project: EditorStateStore.getState()})
        })

        ProjectModifyStore.addListener(() => {
            this.forceUpdate()
        })
    }

    addAsset = e => {
        console.log(e.dataTransfer, e.dataTransfer.files[0], e.dataTransfer.items[0]);

        _.each(e.dataTransfer.files, (file, idx) => {
            if (!e.dataTransfer.items[idx].webkitGetAsEntry().isFile) return

            ProjectModifyActions.addAsset({
                name: file.name,
                mimeType: file.type,
                path: file.path,
            })
        })
    }

    changeComposition = (compId, e) =>
    {
        EditorStateActions.changeActiveComposition(compId)
    }

    modifyCompName = (compId, newName) =>
    {
        ProjectModifyActions.modifyComposition(compId, {name: newName})
    }

    openCompositionSettingWindow = compId =>
    {
        const targetComposition = DelirHelper.findCompositionById(this.state.project.project, compId)

        this.setState({
            settingCompositionQuery: {
                id: targetComposition.id,
                name: targetComposition.name,
                width: targetComposition.width,
                height: targetComposition.height,
                framerate: targetComposition.framerate,
                durationFrame: targetComposition.durationFrame,
                samplingRate: targetComposition.samplingRate,
                audioChannels: targetComposition.audioChannels,
            },
            settingCompositionWindowOpened: true,
        })
    }

    settingComoisition = (req: {
        id:string,
        name: string,
        width: string,
        height: string,
        framerate: string,
        durationSeconds: string
    }) => {
        this.setState({
            settingCompositionQuery: null,
            settingCompositionWindowOpened: false,
        })

        ProjectModifyActions.modifyComposition(req.id, req)
    }

    makeNewComposition = (req: {name: string, width: string, height: string, framerate: string, durationSeconds: string}) =>
    {
        if (req == null) return

        // `newCompositionWindowOpened` must be `false` before create Action.
        // this state is not synced to real window show/hide state.
        // if other state changing fired early to set `false`,
        // component updated and open modal window once again by current state.
        this.setState({newCompositionWindowOpened: false})

        ProjectModifyActions.createComposition({
            name: req.name,
            width: req.width | 0,
            height: req.height | 0,
            framerate: req.framerate | 0,
            durationFrames: (req.framerate | 0) * parseInt(req.durationSeconds, 10)
        })
    }

    render()
    {
        const {app, project: {project}} = this.state
        const assets = project ? Array.from(project.assets.values()) : []
        const compositions = project ? Array.from(project.compositions.values()) : []

        return (
            <Pane className='view-assets' allowFocus>
                <NewCompositionWindow
                    show={this.state.newCompositionWindowOpened}
                    width={400}
                    height={350}
                    onHide={this.makeNewComposition}
                    onResponse={this.makeNewComposition}
                />
{'fraction_non_alphanumeric': 0.10335970409945545, 'fraction_numerical': 0.002876810849686633, 'mean_word_length': 2.262064343163539, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, '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': '2547046', 'n_tokens_mistral': 2626, 'n_tokens_neox': 2523, 'n_words': 547}