CalDetail.js 2.03 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
          /> : <View style={{ marginTop: "20%" }}>
Choi Ga Young's avatar
Choi Ga Young committed
51
            <Text style={{ textAlign: "center", fontSize: 20, fontFamily: 'GowunDodum-Regular' }}>내역이 없습니다.</Text>
52
53
          </View>
        }
54
      </SafeAreaView>
Choi Ga Young's avatar
Choi Ga Young committed
55
    </>
Choi Ga Young's avatar
Choi Ga Young committed
56
57
58
59
  )
}
const style = StyleSheet.create({
  Font: {
60
61
62
63
64
65
66
67
68
    fontSize: 20,
    color: '#424242'
  },
  inputColor: {
    color: '#1E90FF'
  },
  outputColor: {
    color: '#dc143c'
  },
Choi Ga Young's avatar
Choi Ga Young committed
69
70
  itemTextNum: {
    flex: 1,
Choi Ga Young's avatar
Choi Ga Young committed
71
72
    textAlign: "center",
    fontFamily: 'GowunDodum-Regular'
Choi Ga Young's avatar
Choi Ga Young committed
73
  },
74
  itemText: {
Choi Ga Young's avatar
Choi Ga Young committed
75
76
    flex: 1,
    fontFamily: 'GowunDodum-Regular'
Choi Ga Young's avatar
Choi Ga Young committed
77
78
79
80
  }
});

export default DetailInfo;