DetailInfo.js 1.87 KB
Newer Older
1
import React, { useEffect, useState } from 'react';
2
import { SafeAreaView, View, Text, StyleSheet, FlatList } from 'react-native';
3
4
5
import calApi from './db/calendarInfo.api';

const DetailItem = ({ item }) => {
6

7
  return (
8
9
    <>
      <View style={{
10
11
12
13
14
15
16
17
18
19
        flexDirection: "row", padding: "5%", borderColor: '#d3d3d3', //light grey
        borderWidth: 1, borderTopWidth: 0,
      }}>
        <Text style={item.type === 1 ? style.inputColor : style.outputColor}>{item.category}</Text>
        <Text style={[style.itemText, style.Font]}>{item.contents}</Text>
        <Text style={[style.itemText, style.Font]}>{item.price}</Text>
      </View>
    </>
  );
};
Choi Ga Young's avatar
Choi Ga Young committed
20

Choi Ga Young's avatar
Choi Ga Young committed
21
22
23
const DetailInfo = ({ route }) => {
  console.log('route', route.params)
  console.log('---------------------------')
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  const [resData, setResData] = useState([])
  const getDetailData = async () => {
    try {
      const resdata = await calApi.detailData({ findDate: route.params })
      console.log('resdata', resdata)
      setResData(resdata)
    } catch (error) {
      console.log('error in getDetailData', error)
    }
  }
  const renderDetail = ({ item }) => {
    return (
      <DetailItem item={item} />
    )
  }
  useEffect(() => {
    getDetailData()
  }, [])
Choi Ga Young's avatar
Choi Ga Young committed
42
43
  return (
    <>
44
      <SafeAreaView>
45
46
47
48
49
50
51
52
53
54
        {
          resData.length != 0 ? <FlatList
            data={resData}
            renderItem={renderDetail}
            keyExtractor={item => item.id}
          /> : <View>
            <Text style={{textAlign:"center", fontSize:20}}>내역이 없습니다.</Text>
          </View>
        }

55
      </SafeAreaView>
Choi Ga Young's avatar
Choi Ga Young committed
56
    </>
Choi Ga Young's avatar
Choi Ga Young committed
57
58
59
60
  )
}
const style = StyleSheet.create({
  Font: {
61
62
63
64
65
66
67
68
69
70
71
72
73
    fontSize: 20,
    color: '#424242'
  },
  inputColor: {
    color: '#1E90FF'
  },
  outputColor: {
    color: '#dc143c'
  },
  itemText: {
    paddingRight: "10%",
    paddingLeft: "20%",
    // alignItems:"center"
Choi Ga Young's avatar
Choi Ga Young committed
74
75
76
77
  }
});

export default DetailInfo;