CalDetail.js 2.65 KB
Newer Older
Choi Ga Young's avatar
Choi Ga Young committed
1
2
3
import React, { useState } from 'react';
import { SafeAreaView, View, Text, StyleSheet, FlatList, TouchableOpacity } from 'react-native';
import { useFocusEffect } from '@react-navigation/native';
4
import calApi from './db/calendarInfo.api';
Choi Ga Young's avatar
Choi Ga Young committed
5
6
7
8
9
10
11
12
13
14
15
16
17
const DetailItem = ({ item, onPress }) => {
  let item_color
  switch (item.type) {
    case 1:
      item_color = style.inputColor;
      break;
    case 2:
      item_color = style.outputColor;
      break;
    case 3:
      item_color = style.moveColor;
      break;
  }
18

19
  return (
Choi Ga Young's avatar
Choi Ga Young committed
20
    <TouchableOpacity onPress={onPress}>
21
      <View style={{
Choi Ga Young's avatar
Choi Ga Young committed
22
        padding: "5%", borderColor: '#d3d3d3', //light grey
23
24
        borderWidth: 1, borderTopWidth: 0,
      }}>
Choi Ga Young's avatar
Choi Ga Young committed
25
26
27
28
29
30
31
32
33
34
35
        <View style={{ flexDirection: "row" }}>
          <Text style={[style.itemText, item_color]}>{item.category}</Text>
          <Text style={[style.itemTextNum, style.Font]}>{item.contents}</Text>
          <Text style={[style.itemTextNum, style.Font]}>{(item.price).toLocaleString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}</Text>
        </View>
        {item.asset ?
          <Text style={[style.itemTextNum, style.Font]}>
            {'(' + item.asset + '>' + item.deposit_asset + ')'}
          </Text>
          : null}

36
      </View>
Choi Ga Young's avatar
Choi Ga Young committed
37
    </TouchableOpacity>
38
39
  );
};
Choi Ga Young's avatar
Choi Ga Young committed
40

Choi Ga Young's avatar
Choi Ga Young committed
41
const DetailInfo = ({ route, navigation }) => {
42
43
44
45
46
47
48
49
50
51
52
  const [resData, setResData] = useState([])
  const getDetailData = async () => {
    try {
      const resdata = await calApi.detailData({ findDate: route.params })
      setResData(resdata)
    } catch (error) {
      console.log('error in getDetailData', error)
    }
  }
  const renderDetail = ({ item }) => {
    return (
Choi Ga Young's avatar
Choi Ga Young committed
53
      <DetailItem item={item} onPress={() => navigation.navigate('UpdatePage', [route.params, item])} />
54
55
    )
  }
Choi Ga Young's avatar
Choi Ga Young committed
56
57
58
59
60
61
62

  useFocusEffect(
    React.useCallback(() => {
      getDetailData()
    }, [])
  );

Choi Ga Young's avatar
Choi Ga Young committed
63
64
  return (
    <>
65
      <SafeAreaView>
66
        {
Choi Ga Young's avatar
Choi Ga Young committed
67
          resData.length !== 0 ? <FlatList
68
69
70
            data={resData}
            renderItem={renderDetail}
            keyExtractor={item => item.id}
Choi Ga Young's avatar
Choi Ga Young committed
71
          /> : <View style={{ margin: "20%" }}>
Choi Ga Young's avatar
Choi Ga Young committed
72
            <Text style={{ textAlign: "center", fontSize: 20, fontFamily: 'GowunDodum-Regular' }}>내역이 없습니다.</Text>
73
          </View>
Choi Ga Young's avatar
Choi Ga Young committed
74
        }
75
      </SafeAreaView>
Choi Ga Young's avatar
Choi Ga Young committed
76
    </>
Choi Ga Young's avatar
Choi Ga Young committed
77
78
79
80
  )
}
const style = StyleSheet.create({
  Font: {
81
82
83
84
85
86
87
88
89
    fontSize: 20,
    color: '#424242'
  },
  inputColor: {
    color: '#1E90FF'
  },
  outputColor: {
    color: '#dc143c'
  },
Choi Ga Young's avatar
Choi Ga Young committed
90
91
  itemTextNum: {
    flex: 1,
Choi Ga Young's avatar
Choi Ga Young committed
92
93
    textAlign: "center",
    fontFamily: 'GowunDodum-Regular'
Choi Ga Young's avatar
Choi Ga Young committed
94
  },
95
  itemText: {
Choi Ga Young's avatar
Choi Ga Young committed
96
97
    flex: 1,
    fontFamily: 'GowunDodum-Regular'
Choi Ga Young's avatar
Choi Ga Young committed
98
99
100
  },
  moveColor: {
    color: '#646d75'
Choi Ga Young's avatar
Choi Ga Young committed
101
102
103
104
  }
});

export default DetailInfo;