| 
									
										
										
										
											2023-01-03 11:55:46 -08:00
										 |  |  | // Copyright 2020 Signal Messenger, LLC
 | 
					
						
							| 
									
										
										
										
											2020-10-30 15:34:04 -05:00
										 |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  | import * as React from 'react'; | 
					
						
							| 
									
										
										
										
											2021-05-03 18:24:40 -05:00
										 |  |  | import { boolean, number, select, text } from '@storybook/addon-knobs'; | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-17 20:30:08 -04:00
										 |  |  | import { setupI18n } from '../../util/setupI18n'; | 
					
						
							| 
									
										
										
										
											2022-11-16 12:18:02 -08:00
										 |  |  | import { DurationInSeconds } from '../../util/durations'; | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  | import enMessages from '../../../_locales/en/messages.json'; | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { Props } from './TimerNotification'; | 
					
						
							|  |  |  | import { TimerNotification } from './TimerNotification'; | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | const i18n = setupI18n('en', enMessages); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | export default { | 
					
						
							|  |  |  |   title: 'Components/Conversation/TimerNotification', | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | const createProps = (overrideProps: Partial<Props> = {}): Props => ({ | 
					
						
							|  |  |  |   i18n, | 
					
						
							|  |  |  |   type: select( | 
					
						
							|  |  |  |     'type', | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       fromOther: 'fromOther', | 
					
						
							|  |  |  |       fromMe: 'fromMe', | 
					
						
							|  |  |  |       fromSync: 'fromSync', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     overrideProps.type || 'fromOther' | 
					
						
							|  |  |  |   ), | 
					
						
							|  |  |  |   title: text('title', overrideProps.title || ''), | 
					
						
							| 
									
										
										
										
											2021-05-03 18:24:40 -05:00
										 |  |  |   ...(boolean('disabled', overrideProps.disabled || false) | 
					
						
							|  |  |  |     ? { | 
					
						
							|  |  |  |         disabled: true, | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     : { | 
					
						
							|  |  |  |         disabled: false, | 
					
						
							| 
									
										
										
										
											2022-11-16 12:18:02 -08:00
										 |  |  |         expireTimer: DurationInSeconds.fromMillis( | 
					
						
							|  |  |  |           number( | 
					
						
							|  |  |  |             'expireTimer', | 
					
						
							|  |  |  |             ('expireTimer' in overrideProps ? overrideProps.expireTimer : 0) || | 
					
						
							|  |  |  |               0 | 
					
						
							|  |  |  |           ) | 
					
						
							| 
									
										
										
										
											2021-05-03 18:24:40 -05:00
										 |  |  |         ), | 
					
						
							|  |  |  |       }), | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function SetByOther(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							| 
									
										
										
										
											2022-11-16 12:18:02 -08:00
										 |  |  |     expireTimer: DurationInSeconds.fromHours(1), | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  |     type: 'fromOther', | 
					
						
							|  |  |  |     title: 'Mr. Fire', | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <> | 
					
						
							|  |  |  |       <TimerNotification {...props} /> | 
					
						
							|  |  |  |       <div style={{ padding: '1em' }} /> | 
					
						
							| 
									
										
										
										
											2021-05-03 18:24:40 -05:00
										 |  |  |       <TimerNotification {...props} disabled /> | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  |     </> | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function SetByOtherWithALongName(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2021-09-02 16:23:27 -05:00
										 |  |  |   const longName = '🦴🧩📴'.repeat(50); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const props = createProps({ | 
					
						
							| 
									
										
										
										
											2022-11-16 12:18:02 -08:00
										 |  |  |     expireTimer: DurationInSeconds.fromHours(1), | 
					
						
							| 
									
										
										
										
											2021-09-02 16:23:27 -05:00
										 |  |  |     type: 'fromOther', | 
					
						
							|  |  |  |     title: longName, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <> | 
					
						
							|  |  |  |       <TimerNotification {...props} /> | 
					
						
							|  |  |  |       <div style={{ padding: '1em' }} /> | 
					
						
							|  |  |  |       <TimerNotification {...props} disabled /> | 
					
						
							|  |  |  |     </> | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | SetByOtherWithALongName.story = { | 
					
						
							|  |  |  |   name: 'Set By Other (with a long name)', | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2021-09-02 16:23:27 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function SetByYou(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							| 
									
										
										
										
											2022-11-16 12:18:02 -08:00
										 |  |  |     expireTimer: DurationInSeconds.fromHours(1), | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  |     type: 'fromMe', | 
					
						
							|  |  |  |     title: 'Mr. Fire', | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <> | 
					
						
							|  |  |  |       <TimerNotification {...props} /> | 
					
						
							|  |  |  |       <div style={{ padding: '1em' }} /> | 
					
						
							| 
									
										
										
										
											2021-05-03 18:24:40 -05:00
										 |  |  |       <TimerNotification {...props} disabled /> | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  |     </> | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function SetBySync(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							| 
									
										
										
										
											2022-11-16 12:18:02 -08:00
										 |  |  |     expireTimer: DurationInSeconds.fromHours(1), | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  |     type: 'fromSync', | 
					
						
							|  |  |  |     title: 'Mr. Fire', | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <> | 
					
						
							|  |  |  |       <TimerNotification {...props} /> | 
					
						
							|  |  |  |       <div style={{ padding: '1em' }} /> | 
					
						
							| 
									
										
										
										
											2021-05-03 18:24:40 -05:00
										 |  |  |       <TimerNotification {...props} disabled /> | 
					
						
							| 
									
										
										
										
											2020-08-25 17:41:43 -07:00
										 |  |  |     </> | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } |