1
- import { Timestamp } from "firebase/firestore"
2
- import { useMediaQuery } from "usehooks-ts"
3
- import { Testimony } from "../functions/src/testimony/types"
4
- import { Bill , BillContent } from "./db"
5
-
6
1
const billIdFormat = / ^ (?< chamber > \D + ) (?< number > \d + ) $ /
7
2
8
3
/** Formats H123 as H.123 */
@@ -15,56 +10,5 @@ export const formatBillId = (id: string) => {
15
10
}
16
11
}
17
12
18
- const MISSING_TIMESTAMP = Timestamp . fromMillis ( 0 )
19
- export const formatTimestamp = ( t ?: Timestamp ) => {
20
- if ( ! t || t . toMillis ( ) == MISSING_TIMESTAMP . toMillis ( ) ) {
21
- return undefined
22
- }
23
- return t . toDate ( ) . toLocaleDateString ( )
24
- }
25
-
26
- export const FormattedBillTitle = ( { bill } : { bill : Bill | BillContent } ) => {
27
- const isMobile = useMediaQuery ( "(max-width: 768px)" )
28
- const billInfo = "content" in bill ? bill . content : bill
29
-
30
- const { BillNumber, Title } = billInfo
31
-
32
- return (
33
- < div className = "mt-2" >
34
- { formatBillId ( BillNumber ) } :{ " " }
35
- { isMobile ? Title . substring ( 0 , 45 ) + "..." : Title }
36
- </ div >
37
- )
38
- }
39
-
40
- export const FormattedTestimonyTitle = ( {
41
- testimony
42
- } : {
43
- testimony : Testimony
44
- } ) => {
45
- const { authorDisplayName, publishedAt, position } = testimony
46
-
47
- return (
48
- < div >
49
- < span >
50
- < b > Author:</ b > { authorDisplayName || "anonymous" }
51
- </ span >
52
- < br > </ br >
53
- < span >
54
- < b > Published on:</ b > { publishedAt . toDate ( ) . toLocaleDateString ( ) }
55
- </ span >
56
- < br > </ br >
57
- < span >
58
- < b > Position:</ b > { position }
59
- </ span >
60
- </ div >
61
- )
62
- }
63
-
64
- export const decodeHtmlCharCodes = ( s : string ) =>
65
- s . replace ( / ( & # ( \d + ) ; ) / g, ( match , capture , charCode ) =>
66
- String . fromCharCode ( charCode )
67
- )
68
-
69
13
export const truncateText = ( s : string | undefined , maxLength : number ) =>
70
14
! ! s && s . length > maxLength ? s . substring ( 0 , maxLength ) + "..." : s
0 commit comments