MemoDetails.js 2.34 KB
Newer Older
YoonDongMin's avatar
YDm    
YoonDongMin committed
1
import React, { useState, useEffect } from 'react';
YoonDongMin's avatar
YdM    
YoonDongMin committed
2
3
4
5
import { StyleSheet, View, Text, Button, Pressable, TouchableWithoutFeedback, Keyboard } from 'react-native';
import { globalStyles } from '../styles/global';
import InputBox from '../components/InputBox';
import StyledButton from '../components/StyledButton';
YoonDongMin's avatar
YDm    
YoonDongMin committed
6
7
import DatePicker from '../components/DatePicker.js';
import memoApi from '../db/memoPage.api';
YoonDongMin's avatar
YdM    
YoonDongMin committed
8
9


YoonDongMin's avatar
YDm    
YoonDongMin committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function MemoDetails({ route, navigation }) {
    const {item, loadMemos} = route.params
    const getDate = () => {
        var date = new Date();
        return (String(date.toJSON()).split(/T/)[0])
    }
    const [date, setDate] = useState(getDate())
    const [message, setMessage] = useState('')
    const onUpdateHandle = async () => {
        await memoApi.updateMemo({ date, message }, item.id)
        loadMemos()
        navigation.navigate('MemoPage')
        // navigation.goBack()
        // navigation.dispatch( navigation.navigate('MemoPage')); 

    }
YoonDongMin's avatar
YdM    
YoonDongMin committed
26

YoonDongMin's avatar
YDm    
YoonDongMin committed
27
28
29
30
    useEffect(() => {
        setDate(String(item.date))
        setMessage(item.message)
    }, [])
YoonDongMin's avatar
YdM    
YoonDongMin committed
31
32
33
34
35
36
37

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

YoonDongMin's avatar
YdM    
YoonDongMin committed
51
52
53
54
                </View>
                <View style={style.buttonRow}>
                    <StyledButton
                        name="수정"
YoonDongMin's avatar
YDm    
YoonDongMin committed
55
                        onPress={() => { onUpdateHandle() }}
YoonDongMin's avatar
YdM    
YoonDongMin committed
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
81
82
83
84
85
86
87
                        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;