DetailInfo.js 1.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import React, { useEffect, useState } from 'react';
import { SafeAreaView, View, Text, StyleSheet, FlatList, TextComponent } from 'react-native';
import calApi from './db/calendarInfo.api';

const DetailItem = ({ item }) => {
  return (
    <>{
      item != [] ? <View style={{
        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> : <View>
        <Text>내역이 없습니다.</Text>
      </View>
    }

    </>
  );
};
Choi Ga Young's avatar
Choi Ga Young committed
23

Choi Ga Young's avatar
Choi Ga Young committed
24
25
26
const DetailInfo = ({ route }) => {
  console.log('route', route.params)
  console.log('---------------------------')
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  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
45
46
  return (
    <>
47
48
49
50
51
52
53
      <SafeAreaView>
        <FlatList
          data={resData}
          renderItem={renderDetail}
          keyExtractor={item => item.id}
        />
      </SafeAreaView>
Choi Ga Young's avatar
Choi Ga Young committed
54
    </>
Choi Ga Young's avatar
Choi Ga Young committed
55
56
57
58
  )
}
const style = StyleSheet.create({
  Font: {
59
60
61
62
63
64
65
66
67
68
69
70
71
    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
72
73
74
75
  }
});

export default DetailInfo;