MainLayer.js 3.52 KB
Newer Older
Spark's avatar
Spark committed
1
2
import React, { useEffect, useState } from 'react'
import { Button, Image, Row, ButtonGroup, Form, Col } from 'react-bootstrap';
Spark's avatar
Spark committed
3
import { Link } from 'react-router-dom';
Spark's avatar
layout    
Spark committed
4
import '../App.css'
Spark's avatar
Spark committed
5
import UserInfo from './UserInfo';
Spark's avatar
client    
Spark committed
6
import { kakaoLogout } from '../utils/Oauth';
Spark's avatar
Spark committed
7
import axios from 'axios';
8

Spark's avatar
layout    
Spark committed
9
10
11
12
13
14
15

function MainLayer() {

    const boxstyled = {
        border: 'solid',
        color: 'rgba(195, 195, 195, 0.753)',
        borderRadius: '20px',
16
        borderWidth: '3px',
Spark's avatar
layout    
Spark committed
17
18
        width: '100%',
        backgroundSize: 'contain',
19
        textDecorationColor: 'none'
Spark's avatar
layout    
Spark committed
20
21
22
23
    }

    const btnstyled = {
        background: 'rgb(110, 189, 142)',
Spark's avatar
Spark committed
24
25
        margin: 'auto',
        marginBottom: '0.5em',
Spark's avatar
layout    
Spark committed
26
27
        display: 'flex',
        justifyContent: 'center',
Spark's avatar
Spark committed
28
        width: '100%',
Spark's avatar
layout    
Spark committed
29
30
31
        borderWidth: '2px',
        borderColor: 'rgba(195, 195, 195, 0.753)',
        borderRadius: '20px',
32
33
        textDecorationColor: 'none',
        color: 'white'
Spark's avatar
layout    
Spark committed
34
35
    }

Spark's avatar
Spark committed
36
    const logined = localStorage.getItem('nickname')
Spark's avatar
Spark committed
37
38
39
40
41
42
43
    const [airUsing, setAirUsing] = useState(false)

    function aircondiCheck() {
        setAirUsing(!airUsing)
        localStorage.setItem('using-aircondition', !airUsing);
    }

Spark's avatar
Spark committed
44
45
46
47
48
49
50
51
52
53
    useEffect(() => {
        const airUsingLocal = localStorage.getItem('using-aircondition')
        if (airUsingLocal === 'true') {
            return setAirUsing(true)
        }
        else {
            return setAirUsing(false)
        }
    });

Spark's avatar
layout    
Spark committed
54
    return (
Spark's avatar
Spark committed
55
        <Col>
Spark's avatar
Spark committed
56
57
            <Row className='d-flex align-items-center m-auto w-100 p-0'>
                <Link to='/' className='p-0 m-auto'>
58
59
                    <Image src='/images/EUE11.jpg' alt='EUE' style={boxstyled} />
                </Link>
Spark's avatar
layout    
Spark committed
60
61
            </Row>

62
            <Row className='m-auto d-flex justify-content-center w-100'>
Spark's avatar
Spark committed
63
                <UserInfo />
64
            </Row>
Spark's avatar
Spark committed
65
66
67
68
69
70

            {logined &&
                <Form
                    key='checkbox' className="d-flex  justify-content-center w-100" style={{ flexDirection: 'row-reverse' }}>
                    <Form.Check
                        type='switch'
Spark's avatar
Spark committed
71
                        id='airconditioner'
Spark's avatar
Spark committed
72
73
74
75
76
77
                        label='에어컨 사용중'
                        onChange={aircondiCheck}
                        checked={airUsing}
                    />
                </Form>
            }
Spark's avatar
Spark committed
78

79
80
            <Row className='d-flex justify-content-center align-items-center my-2 mx-auto w-100'>
                <ButtonGroup vertical className='m-auto' style={{ width: '100%', flexDirection: 'column' }}>
Spark's avatar
Spark committed
81
                    {logined ?
Spark's avatar
Spark committed
82
83
                        //true
                        <Button variant='light' style={btnstyled} onClick={kakaoLogout}>
84
85
86
                            로그아웃
                        </Button>
                        :
Spark's avatar
Spark committed
87
                        //false
Spark's avatar
Spark committed
88
89
90
91
                        <Button variant='light' style={btnstyled}>
                            <Link to='/login' id='btnlink'>
                                로그인
                            </Link>
92
93
                        </Button>
                    }
Spark's avatar
Spark committed
94
                    {!logined &&
Spark's avatar
Spark committed
95
96
97
98
99
100
                        <Button variant='light' style={btnstyled}>
                            <Link to='/signup' id='btnlink'>
                                회원가입
                            </Link>
                        </Button>
                    }
Spark's avatar
Spark committed
101

Spark's avatar
layout    
Spark committed
102
103
                </ButtonGroup>
            </Row>
104
105
106
            <Row className='m-auto justify-content-center w-100' id='contour'>
                |
            </Row>
Spark's avatar
Spark committed
107
        </Col>
Spark's avatar
layout    
Spark committed
108
109
110
111
    );
}

export default MainLayer