MemoDetails.js 2.3 KB
Newer Older
YoonDongMin's avatar
YDm    
YoonDongMin committed
1
import React, { useState, useEffect } from 'react';
YoonDongMin's avatar
0810DM    
YoonDongMin committed
2
import { StyleSheet, View, TouchableWithoutFeedback, Keyboard, LogBox } from 'react-native';
YoonDongMin's avatar
YdM    
YoonDongMin committed
3
4
import InputBox from '../components/InputBox';
import StyledButton from '../components/StyledButton';
YoonDongMin's avatar
YDm    
YoonDongMin committed
5
6
import DatePicker from '../components/DatePicker.js';
import memoApi from '../db/memoPage.api';
7
import { getDateStr } from '../utils/dateFunction';
YoonDongMin's avatar
YdM    
YoonDongMin committed
8

YoonDongMin's avatar
0810DM    
YoonDongMin committed
9
10


YoonDongMin's avatar
YDm    
YoonDongMin committed
11
function MemoDetails({ route, navigation }) {
12
13
14
15
    const { item, loadMemos } = route.params
    const getDates = () => {
        const date = new Date();
        return (getDateStr(date))
YoonDongMin's avatar
YDm    
YoonDongMin committed
16
    }
17
    const [date, setDate] = useState(getDates())
YoonDongMin's avatar
YDm    
YoonDongMin committed
18
19
20
21
22
23
    const [message, setMessage] = useState('')
    const onUpdateHandle = async () => {
        await memoApi.updateMemo({ date, message }, item.id)
        loadMemos()
        navigation.navigate('MemoPage')
    }
YoonDongMin's avatar
0810DM    
YoonDongMin committed
24
    LogBox.ignoreLogs(['Non-serializable values were found in the navigation state']);
YoonDongMin's avatar
YDm    
YoonDongMin committed
25
26
27
28
    useEffect(() => {
        setDate(String(item.date))
        setMessage(item.message)
    }, [])
YoonDongMin's avatar
YdM    
YoonDongMin committed
29
30
31
32
33
34
35

    return (
        <TouchableWithoutFeedback onPress={() => {
            Keyboard.dismiss();
        }}>
            <View style={{ flex: 1 }}>
                <View>
YoonDongMin's avatar
YDm    
YoonDongMin committed
36
                    <DatePicker
YoonDongMin's avatar
YdM    
YoonDongMin committed
37
                        inputTitle="날짜"
YoonDongMin's avatar
YDm    
YoonDongMin committed
38
39
                        date={date}
                        setDate={setDate}
YoonDongMin's avatar
YdM    
YoonDongMin committed
40
41
42
                    />
                    <InputBox
                        inputTitle="내용"
YoonDongMin's avatar
YDm    
YoonDongMin committed
43
                        value={message}
YoonDongMin's avatar
YdM    
YoonDongMin committed
44
                        onChangeText={
YoonDongMin's avatar
YDm    
YoonDongMin committed
45
                            (message) => setMessage(message)
YoonDongMin's avatar
YdM    
YoonDongMin committed
46
47
                        }
                    />
YoonDongMin's avatar
YDm    
YoonDongMin committed
48

YoonDongMin's avatar
YdM    
YoonDongMin committed
49
50
51
52
                </View>
                <View style={style.buttonRow}>
                    <StyledButton
                        name="수정"
YoonDongMin's avatar
YDm    
YoonDongMin committed
53
                        onPress={() => { onUpdateHandle() }}
YoonDongMin's avatar
YdM    
YoonDongMin committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
                        style={style.submitButton}
                    />
                </View>
            </View>
        </TouchableWithoutFeedback>
    )
}

const style = StyleSheet.create({

    buttonRow: {
        flexDirection: 'row',
        alignItems: "center",
        marginHorizontal: 10,
        marginVertical: 3,
    },
    submitButton: {
        flex: 1,
        height: 50,
    },
    cancelButton: {
        flex: 1,
        height: 50,
    }
});

export default MemoDetails;