* Creates a new post for the current user.
(title: string, text: string)
| 564 | * Creates a new post for the current user. |
| 565 | */ |
| 566 | function newPostForCurrentUser(title: string, text: string) { |
| 567 | const userId = auth.currentUser!.uid; |
| 568 | |
| 569 | return new Promise((resolve) => { |
| 570 | onValue( |
| 571 | ref(database, '/users/' + userId), |
| 572 | function (snapshot) { |
| 573 | const username = |
| 574 | (snapshot.val() && snapshot.val().username) || 'Anonymous'; |
| 575 | return writeNewPost( |
| 576 | auth.currentUser!.uid, |
| 577 | username, |
| 578 | auth.currentUser!.photoURL, |
| 579 | title, |
| 580 | text, |
| 581 | ).then(resolve); |
| 582 | }, |
| 583 | { onlyOnce: true }, |
| 584 | ); |
| 585 | }); |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * Displays the given section element and changes styling of the given button. |