|
| 1 | +/** |
| 2 | + * |
| 3 | + * Copyright 2018 Google Inc. All rights reserved. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +import { LoginButton } from './components/sc-login.js'; |
| 18 | +import { CommentForm } from './components/sc-comment-form.js'; |
| 19 | +import { CommentList } from './components/sc-comment-list.js'; |
| 20 | +import { Comment } from './components/sc-comment.js'; |
| 21 | + |
| 22 | +customElements.define('sc-login', LoginButton); |
| 23 | +customElements.define('sc-comment-form', CommentForm); |
| 24 | +customElements.define('sc-comment-list', CommentList); |
| 25 | +customElements.define('sc-comment', Comment); |
| 26 | + |
| 27 | +const scLogin = document.querySelector('sc-login'); |
| 28 | +const scForm = document.querySelector('sc-comment-form'); |
| 29 | + |
| 30 | +scForm.addEventListener('comment-sent', e => { |
| 31 | + const commentsRef = firebase.firestore().collection('comments'); |
| 32 | + commentsRef.add({ |
| 33 | + text: e.detail.text, |
| 34 | + photoUrl: scLogin.user.photoURL, |
| 35 | + authorName: scLogin.user.displayName, |
| 36 | + timestamp: firebase.firestore.FieldValue.serverTimestamp() |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | +scLogin.addEventListener('on-auth', e => { |
| 41 | + if(e.detail) { |
| 42 | + scLogin.classList.add('sc-hidden'); |
| 43 | + } else { |
| 44 | + scLogin.classList.remove('sc-hidden'); |
| 45 | + } |
| 46 | +}); |
0 commit comments