DetailInfo.js 1.92 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
        flexDirection: "row", padding: "5%", borderColor: '#d3d3d3', //light grey
        borderWidth: 1, borderTopWidth: 0,
      }}>
Choi Ga Young's avatar
Choi Ga Young committed
13
14
15
        <Text style={[style.itemText, item.type === 1 ? style.inputColor : style.outputColor]}>{item.category}</Text>
        <Text style={[style.itemTextNum, style.Font]}>{item.contents}</Text>
        <Text style={[style.itemTextNum, style.Font]}>{item.price}</Text>
16
17
18
19
      </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
        {
          resData.length != 0 ? <FlatList
            data={resData}
            renderItem={renderDetail}
            keyExtractor={item => item.id}
Choi Ga Young's avatar
Choi Ga Young committed
50
51
          /> : <View style={{ marginTop: "20%" }}>
            <Text style={{ textAlign: "center", fontSize: 20 }}>내역이 없습니다.</Text>
52
53
54
          </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
    fontSize: 20,
    color: '#424242'
  },
  inputColor: {
    color: '#1E90FF'
  },
  outputColor: {
    color: '#dc143c'
  },
Choi Ga Young's avatar
Choi Ga Young committed
70
71
72
73
  itemTextNum: {
    flex: 1,
    textAlign: "center"
  },
74
  itemText: {
Choi Ga Young's avatar
Choi Ga Young committed
75
    flex: 1
Choi Ga Young's avatar
Choi Ga Young committed
76
77
78
79
  }
});

export default DetailInfo;