Skip to content

Commit

Permalink
Default disappearing message timeout fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny-signal committed Jun 25, 2021
1 parent c9415dc commit cd28e71
Show file tree
Hide file tree
Showing 25 changed files with 449 additions and 157 deletions.
2 changes: 1 addition & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@
},
"disappearingMessages": {
"message": "Disappearing messages",
"description": "Conversation menu option to enable disappearing messages. Title of the settings section for Disappearing Messages"
"description": "Conversation menu option to enable disappearing messages. Title of the settings section for Disappearing Messages. Label of the disappearing timer select in group creation flow"
},
"disappearingMessagesDisabled": {
"message": "Disappearing messages disabled",
Expand Down
2 changes: 1 addition & 1 deletion js/modules/signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const {
} = require('../../ts/components/conversation/StagedLinkPreview');
const {
DisappearingTimeDialog,
} = require('../../ts/components/conversation/DisappearingTimeDialog');
} = require('../../ts/components/DisappearingTimeDialog');

// State
const { createTimeline } = require('../../ts/state/roots/createTimeline');
Expand Down
116 changes: 57 additions & 59 deletions stylesheets/_modules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2366,8 +2366,10 @@ $timer-icons: '55', '50', '45', '40', '35', '30', '25', '20', '15', '10', '05',
}

// Module: Timer Notification
// Module: Universal Timer Notification

.module-timer-notification {
.module-timer-notification,
.module-universal-timer-notification {
text-align: center;

@include light-theme {
Expand All @@ -2376,62 +2378,52 @@ $timer-icons: '55', '50', '45', '40', '35', '30', '25', '20', '15', '10', '05',
@include dark-theme {
color: $color-gray-05;
}
}

.module-timer-notification__icon-container {
margin-left: auto;
margin-right: auto;
display: inline-flex;
flex-direction: row;
align-items: center;
margin-bottom: 4px;
}

.module-timer-notification__icon {
height: 20px;
width: 20px;
display: inline-block;

@include light-theme {
@include color-svg('../images/icons/v2/timer-24.svg', $color-gray-60);
}
@include dark-theme {
@include color-svg('../images/icons/v2/timer-24.svg', $color-gray-05);
&__icon-container {
margin-left: auto;
margin-right: auto;
display: inline-flex;
flex-direction: row;
align-items: center;
margin-bottom: 8px;
}
}

.module-timer-notification__icon--disabled {
@include light-theme {
@include color-svg(
'../images/icons/v2/timer-disabled-24.svg',
$color-gray-60
);
}
@include dark-theme {
@include color-svg(
'../images/icons/v2/timer-disabled-24.svg',
$color-gray-05
);
}
}
&__icon {
height: 20px;
width: 20px;
display: inline-block;
opacity: 0.6;

.module-timer-notification__icon-label {
margin-left: 6px;
@include light-theme {
@include color-svg('../images/icons/v2/timer-24.svg', $color-gray-60);
}
@include dark-theme {
@include color-svg('../images/icons/v2/timer-24.svg', $color-gray-05);
}

// Didn't seem centered otherwise
margin-top: 1px;
}
&--disabled {
@include light-theme {
@include color-svg(
'../images/icons/v2/timer-disabled-24.svg',
$color-gray-60
);
}
@include dark-theme {
@include color-svg(
'../images/icons/v2/timer-disabled-24.svg',
$color-gray-05
);
}
}
}

// Module: Universal Timer Notification
&__icon-label {
margin-left: 4px;

.module-universal-timer-notification {
text-align: center;
// Didn't seem centered otherwise
margin-top: 1px;

@include light-theme {
color: $color-gray-60;
}
@include dark-theme {
color: $color-gray-05;
opacity: 0.8;
}
}

Expand Down Expand Up @@ -3070,8 +3062,7 @@ button.module-conversation-details__action-button {
margin-right: 12px;
}

&__info,
&__right-info {
&__info {
@include font-body-2;
margin-top: 4px;

Expand All @@ -3090,14 +3081,6 @@ button.module-conversation-details__action-button {
min-width: 143px;
}

&__right-info {
position: absolute;

@include font-subtitle;

padding-left: 14px;
}

&__actions {
margin-left: 12px;
overflow: hidden;
Expand Down Expand Up @@ -7005,6 +6988,21 @@ button.module-image__border-overlay:focus {
&__form {
display: flex;
flex-direction: column;

&__expire-timer {
display: flex;
flex-direction: row;

margin: 0 16px 16px 16px;

&__label {
margin-right: 12px;
}

.module-disappearing-timer-select {
width: 144px;
}
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions stylesheets/components/DisappearingTimerSelect.scss
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;
}
}
}
1 change: 1 addition & 0 deletions stylesheets/manifest.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
@import './components/ConversationHeader.scss';
@import './components/CustomColorEditor.scss';
@import './components/DisappearingTimeDialog.scss';
@import './components/DisappearingTimerSelect.scss';
@import './components/EditConversationAttributesModal.scss';
@import './components/ForwardMessageModal.scss';
@import './components/GradientDial.scss';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { action } from '@storybook/addon-actions';
import { storiesOf } from '@storybook/react';

import { DisappearingTimeDialog } from './DisappearingTimeDialog';
import { setup as setupI18n } from '../../../js/modules/i18n';
import enMessages from '../../../_locales/en/messages.json';
import { setup as setupI18n } from '../../js/modules/i18n';
import enMessages from '../../_locales/en/messages.json';

import { EXPIRE_TIMERS } from '../../test-both/util/expireTimers';
import { EXPIRE_TIMERS } from '../test-both/util/expireTimers';

const story = storiesOf('Components/DisappearingTimeDialog', module);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import React, { useState } from 'react';

import { ConfirmationDialog } from '../ConfirmationDialog';
import { Select } from '../Select';
import { LocalizerType } from '../../types/Util';
import { Theme } from '../../util/theme';
import { ConfirmationDialog } from './ConfirmationDialog';
import { Select } from './Select';
import { LocalizerType } from '../types/Util';
import { Theme } from '../util/theme';

const CSS_MODULE = 'module-disappearing-time-dialog';

Expand Down
37 changes: 37 additions & 0 deletions ts/components/DisappearingTimerSelect.stories.tsx
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} />
));
106 changes: 106 additions & 0 deletions ts/components/DisappearingTimerSelect.tsx
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>
);
};

0 comments on commit cd28e71

Please sign in to comment.