Schedule.js 3.7 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
import React, { useState, useEffect, useRef } from 'react';
Lee Jin Ju's avatar
Lee Jin Ju committed
2
3
4
5
import Calendar from '@toast-ui/react-calendar';
import "tui-calendar/dist/tui-calendar.css";
import "tui-date-picker/dist/tui-date-picker.css";
import "tui-time-picker/dist/tui-time-picker.css";
Lee Jin Ju's avatar
   
Lee Jin Ju committed
6

Kim, Subin's avatar
Kim, Subin committed
7
8
function Cal(calledday) {
  const calendarRef = useRef();
Kim, Subin's avatar
아아    
Kim, Subin committed
9
  const [day, setDay] = useState(calledday);
Lee Jin Ju's avatar
Lee Jin Ju committed
10
11
12
  const [myTheme, setMyTheme] = useState({
    'common.dayname.color': '#333',
    'common.today.color': '#333',
Kim, Subin's avatar
Kim, Subin committed
13
14
15
    // 'common.creationGuide.color': 'white',
    'common.creationGuide.backgroundColor': 'gray',
    // Theme object to extends default dark theme.
Lee Jin Ju's avatar
Lee Jin Ju committed
16
17
  });

Lee Jin Ju's avatar
   
Lee Jin Ju committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  function getDataAction(target) {
    return target.dataset ? target.dataset.action : target.getAttribute('data-action');
  }

  function onClickNavi(e) {
    const cal = calendarRef.current.getInstance();
    const action = getDataAction(e.target);
  
    switch (action) {
      case 'move-prev':
        cal.prev();
        break;
      case 'move-next':
        cal.next();
        break;
      case 'move-today':
        cal.today();
        break;
      default:
        return;
    }
  
    // setRenderRangeText();
    // setSchedules();
  }

  function useday(day) {
    const cal = calendarRef.current.getInstance();
    cal.setDate(new Date(day));
    cal.changeView('week', true);
    cal.today(new Date(day));
  }

Kim, Subin's avatar
Kim, Subin committed
51
  useEffect(() => {
Lee Jin Ju's avatar
오앙    
Lee Jin Ju committed
52
53
54
    // const cal = calendarRef.current.getInstance();
    // cal.setDate(new Date(day));
    // cal.changeView('week', false);
Kim, Subin's avatar
Kim, Subin committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    // cal.today(new Date(day));

    // calendar.on('clickSchedule', function (event) {
    //   const schedule = event.schedule;

    //   if (lastClickSchedule) {
    //     calendar.updateSchedule(lastClickSchedule.id, lastClickSchedule.calendarId, {
    //       isFocused: false,
    //     });
    //   }
    //   calendar.updateSchedule(schedule.id, schedule.calendarId, {
    //     isFocused: true,
    //   });

    //   lastClickSchedule = schedule;
    //   // open detail view

    //   return (console.log(isFocused))
    // });

  }, [day])
Lee Jin Ju's avatar
Lee Jin Ju committed
76
77

  return (
Lee Jin Ju's avatar
   
Lee Jin Ju committed
78
79
80
81
82
83
84
    <div className="container mt-3">
    <div class="tui-datepicker-input tui-datetime-input tui-has-focus">
    <input type="text" id="datepicker-input" aria-label="Date-Time"></input>
    <span class="tui-ico-date"></span>
</div>
<div id="wrapper" style="margin-top: -1px;"></div>

Lee Jin Ju's avatar
Lee Jin Ju committed
85
    <Calendar
Lee Jin Ju's avatar
   
Lee Jin Ju committed
86
      ref={calendarRef}
Lee Jin Ju's avatar
Lee Jin Ju committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
      height="100%"
      calendars={[
        {
          id: 'Subject',
          bgColor: '#a9a9a9',
          borderColor: '#a9a9a9',
          isReadOnly: 'true'
        }
      ]}
      
      view="week"
      disableDblClick={false}
      disableClick={true}
      isReadOnly={false}
101
            // template={
Kim, Subin's avatar
Kim, Subin committed
102
103
104
105
      //   popupIsAllDay=function {
      //     return display: "none"
      //   }
      // }
Lee Jin Ju's avatar
Lee Jin Ju committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
      schedules={[
        {
          id: '1',
          calendarId: 'Subject',
          category: 'time',
          start: '2020-10-05T11:00:00',
          end: '2020-10-05T12:00:00',
        },
        {
          id: '2',
          calendarId: 'Subject',
          category: 'time',
          start: '2020-10-09T10:00:00',
          end: '2020-10-09T11:00:00',
        },
        {
          id: '3',
          calendarId: 'Subject',
          category: 'time',
          start: '2020-10-08T11:00:00',
          end: '2020-10-08T15:00:00',
        }
      ]}
      scheduleView={['time']}
      taskView={false}
      theme={myTheme}
      timezones={[
        {
          timezoneOffset: 540,
          displayLabel: 'GMT+09:00',
          tooltip: 'Seoul'
        },
      ]}
      useDetailPopup
      useCreationPopup
Kim, Subin's avatar
Kim, Subin committed
141
      view={"week"}
Lee Jin Ju's avatar
Lee Jin Ju committed
142
      week={{
Kim, Subin's avatar
Kim, Subin committed
143
        workweek: true,
Lee Jin Ju's avatar
Lee Jin Ju committed
144
        hourStart: 8,
Kim, Subin's avatar
Kim, Subin committed
145
        hourEnd: 23
Lee Jin Ju's avatar
Lee Jin Ju committed
146
147
      }}
    />
Lee Jin Ju's avatar
   
Lee Jin Ju committed
148
    </div>
Lee Jin Ju's avatar
Lee Jin Ju committed
149
150
151
152
  )
}

export default Cal