Blame view

js/classify/containers/BrandContainer.js 6.84 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
'use strict'

import React, {Component} from 'react';
import ReactNative, {
    StyleSheet,
    Dimensions,
    Platform,
    View,
    Text,
    NativeModules,
    InteractionManager,
    NativeAppEventEmitter,
} from 'react-native'

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as brandActions from '../reducers/brand/brandActions';

import Brand from '../components/brand/Brand';


const actions = [
    brandActions,
];

function mapStateToProps(state) {
    return {
        ...state
    };
}

function mapDispatchToProps(dispatch) {

    const creators = Map()
        .merge(...actions)
        .filter(value => typeof value === 'function')
        .toObject();

    return {
        actions: bindActionCreators(creators, dispatch),
        dispatch
    };
}

class BrandContainer extends Component {
    constructor(props) {
        super(props);
50 51
        this._onPressSlideItem = this._onPressSlideItem.bind(this);
        this._onPressFilter = this._onPressFilter.bind(this);
52
        this._onChannelPressFliter = this._onChannelPressFliter.bind(this);
53 54
        this._onPressSearch = this._onPressSearch.bind(this);
        this._onPressClearHistory = this._onPressClearHistory.bind(this);
55 56
        this._onClickCancelSearch = this._onClickCancelSearch.bind(this);
        this._onSearchTextChange = this._onSearchTextChange.bind(this);
57 58
        this._onPressKeyword = this._onPressKeyword.bind(this);
        this._onPressBrandSearchItem = this._onPressBrandSearchItem.bind(this);
59 60
        this._setBrandData = this._setBrandData.bind(this);
        this._setInitialListSize = this._setInitialListSize.bind(this);
61 62 63 64 65


        this.subscription = NativeAppEventEmitter.addListener(
            'ChannelDidChangeEvent',
            (reminder) => {
66
                this._onChannelPressFliter(reminder.channel);
67 68 69
            }
        );
70 71 72
    }

    componentDidMount() {
73 74
        this.props.actions.getBrandList(1);
        this.props.actions.getBrandResource(1);
75 76
        this.props.actions.searchHistory();
        this.props.actions.hotKeyword();
77 78 79
    }

    componentWillUnmount() {
80
81 82
    }
83 84 85 86
    componentWillUnmount() {
        this.subscription && this.subscription.remove();
    }
87 88
    _onPressSlideItem(data){
        ReactNative.NativeModules.YH_ClassifyHelper.pushBrandVC(data);
89
    }
90
91
    _onPressFilter(value) {
92 93
        this.props.actions.setBrandFilter(value);
    }
94
95 96 97 98
    _setInitialListSize(count){
        this.props.actions.setInitialListSize(count);
    }
99
    _onChannelPressFliter(value){
100 101 102 103 104 105 106 107 108 109 110

        let {
            brandListForBoy,
            brandListForGirl,
            brandListForKid,
            brandListForLifeStyle,
            reourceForBoy,
            reourceForGirl,
            reourceForKid,
            reourceForLifeStyle,
        } = this.props.brand;
111
112 113
        let brandListNeedRequest;
        let reourceNeedRequest;
114
        if (value == 1) {
115 116
            brandListNeedRequest = brandListForBoy.get('hasSuccess');
            reourceNeedRequest = reourceForBoy.get('hasSuccess');
117
        }else if (value == 2) {
118 119
            brandListNeedRequest = brandListForGirl.get('hasSuccess');
            reourceNeedRequest = reourceForGirl.get('hasSuccess');
120
        }else if (value == 3) {
121 122
            brandListNeedRequest = brandListForKid.get('hasSuccess');
            reourceNeedRequest = reourceForKid.get('hasSuccess');
123
        }else if (value == 4) {
124 125 126 127 128 129 130
            brandListNeedRequest = brandListForLifeStyle.get('hasSuccess');
            reourceNeedRequest = reourceForLifeStyle.get('hasSuccess');
        }

        if (!brandListNeedRequest) {
            this.props.actions.getBrandList(value);
        }
131
        if (!reourceNeedRequest) {
132 133
            this.props.actions.getBrandResource(value);
        }
134
        this.props.actions.setInitialListSize(0);
孙凯 authored
135
        this.props.actions.setBrandChannelFilter(value);
136 137
    }
138 139 140 141 142 143 144 145
    _onPressSearch() {
        this.props.actions.setShowSearch(!this.props.brand.showSearch);
    }

    _onPressClearHistory() {
        this.props.actions.clearSearchHistory();
    }
146 147
    _onClickCancelSearch() {
        this.props.actions.setShowSearch(!this.props.brand.showSearch);
148 149
        this.props.actions.setBrandKeyword('');
        this.props.actions.filteBrandForKeyword('');
150 151 152
    }

    _onSearchTextChange(text) {
153
        this.props.actions.setBrandKeyword(text);
154 155 156
        this.props.actions.filteBrandForKeyword(text);
    }
157 158 159 160
    _setBrandData(data,brandChannelFliter) {
        this.props.actions.setBrandData(data,brandChannelFliter);
    }
161 162 163 164 165 166 167 168 169 170
    _onPressKeyword(keyword) {
        this._onSearchTextChange(keyword);
    }

    _onPressBrandSearchItem(url, brandName) {
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
        this.props.actions.insertSearchHistory(brandName);
        this._onClickCancelSearch();
    }
171
    render() {
172
        let {
173
            showSearch,
174
            initialListSize,
175
            isFetching,
孙凯 authored
176
            brandChannelFliter,
177
            brandFliter,
178
            brandListForBoy,
179 180 181
            brandListForGirl,
            brandListForKid,
            brandListForLifeStyle,
182
            reourceForBoy,
183 184 185
            reourceForGirl,
            reourceForKid,
            reourceForLifeStyle,
186
            search,
187
        } = this.props.brand;
188
189 190 191
        return (
            <View style={styles.container}>
                <Brand
192
                    isFetching={isFetching}
193
                    initialListSize={initialListSize}
孙凯 authored
194
                    brandChannelFliter= {brandChannelFliter}
195
                    brandFliter= {brandFliter}
196
                    brandListForBoy= {brandListForBoy}
197 198 199
                    brandListForGirl= {brandListForGirl}
                    brandListForKid= {brandListForKid}
                    brandListForLifeStyle= {brandListForLifeStyle}
200
                    reourceForBoy= {reourceForBoy}
201 202 203
                    reourceForGirl={reourceForGirl}
                    reourceForKid={reourceForKid}
                    reourceForLifeStyle={reourceForLifeStyle}
204 205
                    onPressFilter= {this._onPressFilter}
                    onPressSlideItem= {this._onPressSlideItem}
206
                    onChannelPressFliter={this._onChannelPressFliter}
207 208 209 210
                    showSearch={showSearch}
                    search={search}
                    onPressSearch={this._onPressSearch}
                    onPressClearHistory={this._onPressClearHistory}
211 212
                    onClickCancel={this._onClickCancelSearch}
                    onTextChange={this._onSearchTextChange}
213
                    onPressBrandSearchItem={this._onPressBrandSearchItem}
214 215
                    setBrandData={this._setBrandData}
                    setInitialListSize={this._setInitialListSize}
216 217 218 219 220 221 222 223 224 225 226 227 228 229
                />
            </View>
        );
    }
}

let styles = StyleSheet.create({
    container: {
        flex: 1,
    },

});

export default connect(mapStateToProps, mapDispatchToProps)(BrandContainer);