aboutsummaryrefslogtreecommitdiff
path: root/src/components/mao-tutoring.js
blob: 08bdef5d01849c271f9bd75df9794a6f06668a69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
51
52
53
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/**
@license
Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/

import { html } from '@polymer/lit-element';
import { PageViewElement } from './page-view-element.js';
import { connect } from 'pwa-helpers/connect-mixin.js';

// This element is connected to the Redux store.
import { store } from '../store.js';

//These are the actions needed by this element.
import { requestHours }  from '../actions/firebaseFirestore.js';
import { uploadPicture } from '../actions/firebaseStorage.js'

// These are the }shared styles needed by this element.
import { SharedStyles }       from './shared-styles.js';
import { ButtonSharedStyles } from './button-shared-styles.js';

// Import iron-icon
import '@polymer/iron-icons/communication-icons.js';

// Import paper elements
import '@polymer/paper-input/paper-input.js';
import '@polymer/paper-progress/paper-progress.js';
import '@polymer/paper-card/paper-card.js';
import '@polymer/paper-item/paper-item.js';
import '@polymer/paper-item/paper-icon-item.js';
import '@polymer/paper-icon-button/paper-icon-button.js';
import '@polymer/paper-button/paper-button.js';

// Import other customElements
import '@vaadin/vaadin-date-picker/vaadin-date-picker.js';

class MaoTutoring extends connect(store)(PageViewElement) {
  _render(props) {
    return html`
      ${SharedStyles}
      ${ButtonSharedStyles}

      <style>
      .title {
        grid-area: title;
      }

      .tutorCard, .hoursCard {
        background-color: #f7f7f7;
        padding:          1px;
      }

      .hours-grid {
        display:  grid;
        grid-gap: 10px;

        grid-template-areas:
                        "title"
                        "item1"
                        "item2";
      }

      .approved-card {
        grid-area:  item1;

        background-color: #b7e1cd;
        margin:           1px;
        padding:          0 10px 15px 10px;
      }

      .unapproved-card {
        grid-area:  item2;

        background-color: #fce8b2;
        margin:           1px;
        padding:          0 10px 15px 10px;
      }

      .submit-hours {
        width: 100%;
      }

      paper-card {
        --paper-card-background-color: #f7f7f7;
        display: block;
      }

      .subjectCard, .hopeCard {
        --paper-card-background-color: #87ceeb;
      }

      paper-item {
        display: block;
      }

      paper-button {
        margin-left: auto;
        margin-right: auto;
        display: block;
      }

      h3 {
        text-align: center;
      }

      #datePicker {
        margin-top: 10px;
      }

      .paper-item-link {
      color: inherit;
      text-decoration: none;
      }

      .tutoring-grid {
        display:  grid;
        grid-gap: 10px;

        grid-template-columns: 1fr;
      }

      @media (min-width: 460px) {
        .hours-grid {
          grid-template-areas:
                          "title    title"
                          "item1    item2";
        }

        .tutorCard, .hoursCard {
          padding:  1em;
        }

        .tutoring-grid {
          grid-template-columns: 1fr 1fr;
        }
      }

      .picture-upload {
        display:  flex;
        width:    100%;
        flex-direction: column;
      }

      #uploader {
        appearance: none;
        width: 100%;
      }
      </style>

      <section class="img-section">
        <div class="container">
          <img src="https://ak0.picdn.net/shutterstock/videos/2342780/thumb/1.jpg" alt="Maths">
          <div class="centered">Tutoring</div>
        </div>
      </section>

      <section hidden="${!props.signedIn}">

        <paper-card
        elevation="0"
        class="hoursCard">

          <div class="card-content">

            <div class="hours-grid">

              <div class="title">
                <h2 class="underline">Summmary</h2>
              </div>

              <div class="approved-card">
                <h3>Approved Minutes</h3>
                <div
                class=  "circle"
                style=  "background-color: #0f9d58;">${props.hours*60}</div>
              </div>

              <div class="unapproved-card">
                <h3>Requested Minutes</h3>
                <div
                class=  "circle"
                style=  "background-color: #f4b400;">${props.requestedHours*60}</div>
              </div>

            </div>

          </div>

          <div class="card-actions">
            <paper-button
            class="info"
            id="submit-hours-btn"
            on-tap="${() => this.toggleSubmitFields()}"
            hidden="${props.submitFieldsOpened}"
            raised>
              Submit Hours
            </paper-button>

            <div class="submit-card" hidden="${!props.submitFieldsOpened}">

              <h3>Fill Fields</h3>

              <paper-input
              id=     "timeField"
              label=  "Time"
              type=   "number"
              value=  "15"
              step=   "15"
              max=    "120"
              min=    "15">
                <span slot="suffix">(minutes)</span>
              </paper-input>

              <paper-input id="locationField" label="Location" type="text"></paper-input>

              <paper-input id="traineeField" label="Trainee's Name" type="text"></paper-input>

              <paper-input id="subjectField" label="Math Subject" type="text"></paper-input>

              <vaadin-date-picker id="dateField" placeholder="Choose Date">
              </vaadin-date-picker>

              <div class="picture-upload">
                <paper-input onchange="${() => this.uploadFile()}" id="pictureField" label="Upload Picture With Trainee" type="file" accept="image/png, image/jpeg"></paper-input>
                <paper-progress value="0" max="100" id="uploader"></paper-progress>
              </div>
              
              <br/>

              <paper-button
              class="info"
              id="submit-form-btn"
              on-tap="${() => this.requestHours()}"
              raised>
                Submit Form
              </paper-button>
            </div>
          </div>
        </paper-card>


      </section>

      <section>
        <div class="tutoring-grid">
          <paper-card class="subjectCard">
            <div class="card-actions">
              <h3>Our Hope</h3>
              <p>
                We want to encourage an enviornment of learnin through peer-to-peer tutoring.
                We offer all tutoring in all subjects for mao competitions and school subjects:
              </p>
              <ul>
                <li>Algebra (1 & 2)</li>
                <li>Geometry</li>
                <li>Pre-calculus</li>
                <li>Calculus (AB & BC)</li>
              </ul>
            </div>
          </paper-card>

          <paper-card class="hopeCard">
            <div class="card-actions">
              <h3>Need Help Finiding A Tutor?</h3>
              <p>Please meet with your friends to create tutring sessions.</p>
              <p>Also, you can try the fourm page if you want.</p>
              <p>Otherwise, contact our tutoring coordinator <em>Mike Binkowski</em>.</p>
            </div>

            <div class="card-actions">
              <div role="listbox">
                <paper-icon-item>
                  <iron-icon icon="communication:call" slot="item-icon"></iron-icon>
                 (813) 458-9988 
                </paper-icon-item>
                <a class="paper-item-link" href="mailto:mbinkowski2020@communityschoolnaples.org" tabindex="-1">
                  <paper-icon-item>
                    <iron-icon icon="communication:email" slot="item-icon"></iron-icon>
                    <span style="word-break: break-all;">mbinkowski2020@communityschoolnaples.org</span>
                  </paper-icon-item>
                </a>
              </div>
            </div>
          </paper-card>
        </div>
      </section>
    `;
  }

  static get properties() { return {
    // This is the data from the store.
    signedIn:           Boolean,
    hours:              Number,
    requestedHours:     Number,
    isUploaded:         Boolean,
    pictureName:        String,

    submitFieldsOpened: Boolean
  }}

  _stateChanged(state) {
    this.hours          = state.firebaseFirestore .hours;
    this.requestedHours = state.firebaseFirestore .requestedHours;
    this.signedIn       = state.firebaseAuth      .signedIn;
    this.isUploaded     = state.firebaseStorage   .uploaded;
    this.pictureName    = state.firebaseStorage   .pictureName;

    this.sumbitFieldsOpened = false;
  }

  toggleSubmitFields() {
    this.submitFieldsOpened = !this.submitFieldsOpened;
  }

  requestHours() {
    if(this.shadowRoot && this.isUploaded) {
      var timeElement     = this.shadowRoot.getElementById('timeField');
      var traineeElement  = this.shadowRoot.getElementById('traineeField');
      var subjectElement  = this.shadowRoot.getElementById('subjectField');
      var locationElement = this.shadowRoot.getElementById('locationField');
      var dateElement     = this.shadowRoot.getElementById('dateField');
      var uploaderElement = this.shadowRoot.getElementById('uploader');
      var fileElement     = this.shadowRoot.getElementById('pictureField');

      if( timeElement     .value.trim() === "" ||
          locationElement .value.trim() === "" ||
          traineeElement  .value.trim() === "" ||
          subjectElement  .value.trim() === "" ||
          dateElement     .value        === "") {
            alert("Please fill out all fields when making hours request.");
          } else {
            if(confirm('Are you sure that you want to send this request for hours?')) {
              const timeHours   = (timeElement    .value)
                                  /60;
              const location    = locationElement .value;
              const traineeName = traineeElement  .value;
              const subject     = subjectElement  .value;
              const date        = dateElement     .value;

              store.dispatch(requestHours(timeHours, traineeName, location, subject, date, this.pictureName));

              timeElement     .value  = "";
              traineeElement  .value  = "";
              subjectElement  .value  = "";
              locationElement .value  = "";
              dateElement     .value  = "";
              uploaderElement .value  =  0;
              fileElement     .value  = "";
            }
        }
    } else {
      alert("You must upload an image with your trainee to submit hours.")
    }
  }

  uploadFile() {
    if(this.shadowRoot) {
      var uploader    = this.shadowRoot.getElementById('uploader');
      uploader.value  = 0;

      var file      = this.shadowRoot.getElementById('pictureField').inputElement.inputElement.files[0];

      store.dispatch(uploadPicture(file, uploader));
    }
  }



}

window.customElements.define('mao-tutoring', MaoTutoring);