-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default disappearing message timeout fixes
- Loading branch information
1 parent
c9415dc
commit cd28e71
Showing
25 changed files
with
449 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2021 Signal Messenger, LLC | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
.module-disappearing-timer-select { | ||
position: relative; | ||
|
||
&__info { | ||
position: absolute; | ||
|
||
margin-top: 4px; | ||
padding-left: 14px; | ||
|
||
@include font-subtitle; | ||
|
||
@include light-theme { | ||
color: $color-gray-60; | ||
} | ||
|
||
@include dark-theme { | ||
color: $color-gray-25; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2021 Signal Messenger, LLC | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
import React, { useState } from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
|
||
import { DisappearingTimerSelect } from './DisappearingTimerSelect'; | ||
import { setup as setupI18n } from '../../js/modules/i18n'; | ||
import enMessages from '../../_locales/en/messages.json'; | ||
|
||
const story = storiesOf('Components/DisappearingTimerSelect', module); | ||
|
||
const i18n = setupI18n('en', enMessages); | ||
|
||
type Props = { | ||
initialValue: number; | ||
}; | ||
|
||
const TimerSelectWrap: React.FC<Props> = ({ initialValue }) => { | ||
const [value, setValue] = useState(initialValue); | ||
|
||
return ( | ||
<DisappearingTimerSelect | ||
i18n={i18n} | ||
value={value} | ||
onChange={newValue => setValue(newValue)} | ||
/> | ||
); | ||
}; | ||
|
||
story.add('Initial value: 1 day', () => ( | ||
<TimerSelectWrap initialValue={24 * 3600} /> | ||
)); | ||
|
||
story.add('Initial value 3 days (Custom time)', () => ( | ||
<TimerSelectWrap initialValue={3 * 24 * 3600} /> | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright 2021 Signal Messenger, LLC | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
import React, { useState, ReactNode } from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
import { LocalizerType } from '../types/Util'; | ||
import * as expirationTimer from '../util/expirationTimer'; | ||
import { DisappearingTimeDialog } from './DisappearingTimeDialog'; | ||
|
||
import { Select } from './Select'; | ||
|
||
const CSS_MODULE = 'module-disappearing-timer-select'; | ||
|
||
export type Props = { | ||
i18n: LocalizerType; | ||
|
||
value?: number; | ||
onChange(value: number): void; | ||
}; | ||
|
||
export const DisappearingTimerSelect: React.FC<Props> = (props: Props) => { | ||
const { i18n, value = 0, onChange } = props; | ||
|
||
const [isModalOpen, setIsModalOpen] = useState(false); | ||
|
||
let expirationTimerOptions: ReadonlyArray<{ | ||
readonly value: number; | ||
readonly text: string; | ||
}> = expirationTimer.DEFAULT_DURATIONS_IN_SECONDS.map(seconds => { | ||
const text = expirationTimer.format(i18n, seconds, { | ||
capitalizeOff: true, | ||
}); | ||
return { | ||
value: seconds, | ||
text, | ||
}; | ||
}); | ||
|
||
const isCustomTimeSelected = !expirationTimer.DEFAULT_DURATIONS_SET.has( | ||
value | ||
); | ||
|
||
const onSelectChange = (newValue: string) => { | ||
const intValue = parseInt(newValue, 10); | ||
if (intValue === -1) { | ||
setIsModalOpen(true); | ||
} else { | ||
onChange(intValue); | ||
} | ||
}; | ||
|
||
// Custom time... | ||
expirationTimerOptions = [ | ||
...expirationTimerOptions, | ||
{ | ||
value: -1, | ||
text: i18n( | ||
isCustomTimeSelected | ||
? 'selectedCustomDisappearingTimeOption' | ||
: 'customDisappearingTimeOption' | ||
), | ||
}, | ||
]; | ||
|
||
let modalNode: ReactNode = null; | ||
if (isModalOpen) { | ||
modalNode = ( | ||
<DisappearingTimeDialog | ||
i18n={i18n} | ||
initialValue={value} | ||
onSubmit={newValue => { | ||
setIsModalOpen(false); | ||
onChange(newValue); | ||
}} | ||
onClose={() => setIsModalOpen(false)} | ||
/> | ||
); | ||
} | ||
|
||
let info: ReactNode; | ||
if (isCustomTimeSelected) { | ||
info = ( | ||
<div className={`${CSS_MODULE}__info`}> | ||
{expirationTimer.format(i18n, value)} | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div | ||
className={classNames( | ||
CSS_MODULE, | ||
isCustomTimeSelected ? `${CSS_MODULE}--custom-time` : false | ||
)} | ||
> | ||
<Select | ||
onChange={onSelectChange} | ||
value={isCustomTimeSelected ? -1 : value} | ||
options={expirationTimerOptions} | ||
/> | ||
{info} | ||
{modalNode} | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.