|
| 1 | +import styles from './Header.module.css'; |
| 2 | +import { Fire } from '../icons/Fire.js'; |
| 3 | +import { h } from 'preact'; |
| 4 | +import { useMessaging, useTypedTranslation } from '../types.js'; |
| 5 | +import { Cross } from '../icons/Cross.js'; |
| 6 | +import { useEffect } from 'preact/hooks'; |
| 7 | + |
| 8 | +export function Header({ setResults }) { |
| 9 | + const { t } = useTypedTranslation(); |
| 10 | + const historyPage = useMessaging(); |
| 11 | + useEffect(() => { |
| 12 | + historyPage |
| 13 | + .query({ term: '', limit: 150, offset: 0 }) |
| 14 | + // eslint-disable-next-line promise/prefer-await-to-then |
| 15 | + .then(setResults) |
| 16 | + // eslint-disable-next-line promise/prefer-await-to-then |
| 17 | + .catch((e) => { |
| 18 | + console.log('did catch...', e); |
| 19 | + }); |
| 20 | + }, []); |
| 21 | + return ( |
| 22 | + <div class={styles.root}> |
| 23 | + <div class={styles.controls}> |
| 24 | + <button class={styles.largeButton}> |
| 25 | + <Fire /> |
| 26 | + <span>Clear History and Data...</span> |
| 27 | + </button> |
| 28 | + <button class={styles.largeButton}> |
| 29 | + <Cross /> |
| 30 | + <span>Remove History...</span> |
| 31 | + </button> |
| 32 | + </div> |
| 33 | + <div class={styles.search}> |
| 34 | + <form |
| 35 | + action="" |
| 36 | + onSubmit={(e) => { |
| 37 | + e.preventDefault(); |
| 38 | + const data = new FormData(/** @type {HTMLFormElement} */ (e.target)); |
| 39 | + historyPage |
| 40 | + .query({ term: data.get('term')?.toString() || '', limit: 150, offset: 0 }) |
| 41 | + // eslint-disable-next-line promise/prefer-await-to-then |
| 42 | + .then(setResults) |
| 43 | + // eslint-disable-next-line promise/prefer-await-to-then |
| 44 | + .catch((e) => { |
| 45 | + console.log('did catch...', e); |
| 46 | + }); |
| 47 | + }} |
| 48 | + > |
| 49 | + <input type="search" placeholder={t('search')} class={styles.searchInput} name="term" /> |
| 50 | + </form> |
| 51 | + </div> |
| 52 | + </div> |
| 53 | + ); |
| 54 | +} |
0 commit comments