RateLine.js 2.92 KB
import React, {useEffect} from 'react';
import { Surface, Text,Divider} from 'react-native-paper';
import { View,StyleSheet } from 'react-native';
import {connect} from 'react-redux';
import {load } from '../../reducers/search';
import PromptSearchRate from '../PromptSearch/PromptSearchRate';
const RateLine = ({load,pastRecords }) => {
    useEffect(()=>{
        const get = async () => {
            await load();
        }
        get();
    }, [load]);
    return (
        <Surface style={styles.surface}>
            {pastRecords.length ? 
            <>
                <Text style={styles.message}>당신의 점수 변화를 확인하세요!</Text>
                <View style={styles.scoreContainer}>
                {pastRecords.map((past,index)=> (
                    pastRecords.length - 1 > index  ?
                    <View  key={index} style={styles.past}>
                        <Text style={styles.date, {fontSize:11}}>{past.date.substring(5,7)+'/'+past.date.substring(8,10)}</Text>
                        <Text style={styles.score}>{past.score}</Text>                        
                    </View>
                    :
                    <View  key={index} style={styles.past}>
                    <Text style={styles.date, {fontSize:15}}>{past.date.substring(5,7)+'/'+past.date.substring(8,10)}</Text>
                    <Text style={styles.score, {fontFamily:"ExtraBold", fontSize:25, color: "#4ea1d3"}}>{past.score}</Text>                        
                </View>
                ))} 
                
                </View>                
            </>
             : <PromptSearchRate />
            }
        </Surface>
    );
}
const styles = StyleSheet.create({
    surface: {        
        padding :5,
        flex: 0.3,
        width: '95%',
        flexDirection:'column',
        alignItems: 'center',
        justifyContent: 'center',
        elevation: 2,
        marginTop: 10,
        marginBottom: 10,
        borderRadius: 5,
    },
    info:{
        fontSize:21,
        marginBottom: 10,
        fontFamily:"Bold",
    },
    scoreContainer:{
        flexDirection:'row',
        alignItems : 'center',
        justifyContent: 'space-around',
        width:'100%',
        backgroundColor :'#ececf8',
        padding : 5,
        marginTop : 10,
        marginBottom : 10,
        borderRadius:5,
    },
    data:{ 
        fontFamily:"Son",
        textAlign:'center', 
        marginBottom:10,      
    },
    score:{
        fontSize:20,
        fontFamily:"Bold"
    },
    past:{
        alignItems:'center',
        marginBottom:5
    },
    message:{
        fontFamily:"Son",
        margin : 5,
        fontSize: 25,
        justifyContent: 'flex-start',
    }
});
const RateLineContainer = ( {load,pastRecords } ) => (
    <RateLine load={load} pastRecords={pastRecords} />
);
export default connect(
    ({search})=>({
        pastRecords:search.pastRecords
    }),
    {
        load
    }
)(RateLineContainer);