signal-desktop/ts/components/Preferences.stories.tsx

330 lines
10 KiB
TypeScript
Raw Normal View History

2021-08-18 16:08:14 -04:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { Meta, StoryFn } from '@storybook/react';
2021-08-18 16:08:14 -04:00
import React from 'react';
import { action } from '@storybook/addon-actions';
import type { PropsType } from './Preferences';
2025-04-02 14:57:29 -04:00
import { Page, Preferences } from './Preferences';
2021-08-18 16:08:14 -04:00
import { DEFAULT_CONVERSATION_COLOR } from '../types/Colors';
import { PhoneNumberSharingMode } from '../util/phoneNumberSharingMode';
import { PhoneNumberDiscoverability } from '../util/phoneNumberDiscoverability';
2025-03-26 12:35:32 -07:00
import { EmojiSkinTone } from './fun/data/emojis';
2025-04-02 14:57:29 -04:00
import { DAY, DurationInSeconds, WEEK } from '../util/durations';
2021-08-18 16:08:14 -04:00
2025-03-13 12:52:08 -07:00
const { i18n } = window.SignalContext;
2021-08-18 16:08:14 -04:00
const availableMicrophones = [
{
name: 'DefAuLt (Headphones)',
index: 0,
uniqueId: 'Default',
i18nKey: 'default_communication_device',
},
];
const availableSpeakers = [
{
name: 'Default',
index: 0,
uniqueId: 'Default',
i18nKey: 'default_communication_device',
},
{
name: "Natalie's Airpods (Bluetooth)",
index: 1,
uniqueId: 'aa',
},
{
name: 'UE Boom (Bluetooth)',
index: 2,
uniqueId: 'bb',
},
];
2022-06-06 20:48:02 -04:00
export default {
title: 'Components/Preferences',
2022-07-19 20:47:05 -04:00
component: Preferences,
args: {
i18n,
autoDownloadAttachment: {
photos: true,
videos: false,
audio: false,
documents: false,
},
availableCameras: [
{
deviceId:
'dfbe6effe70b0611ba0fdc2a9ea3f39f6cb110e6687948f7e5f016c111b7329c',
groupId:
'63ee218d2446869e40adfc958ff98263e51f74382b0143328ee4826f20a76f47',
kind: 'videoinput' as MediaDeviceKind,
label: 'FaceTime HD Camera (Built-in) (9fba:bced)',
},
{
deviceId:
'e2db196a31d50ff9b135299dc0beea67f65b1a25a06d8a4ce76976751bb7a08d',
groupId:
'218ba7f00d7b1239cca15b9116769e5e7d30cc01104ebf84d667643661e0ecf9',
kind: 'videoinput' as MediaDeviceKind,
label: 'Logitech Webcam (4e72:9058)',
},
],
2023-11-06 13:19:23 -08:00
availableLocales: ['en'],
availableMicrophones,
availableSpeakers,
2025-04-02 14:57:29 -04:00
backupFeatureEnabled: false,
blockedCount: 0,
customColors: {},
defaultConversationColor: DEFAULT_CONVERSATION_COLOR,
deviceName: 'Work Windows ME',
2025-03-26 12:35:32 -07:00
emojiSkinToneDefault: EmojiSkinTone.None,
2024-02-06 10:35:59 -08:00
phoneNumber: '+1 555 123-4567',
hasAudioNotifications: true,
2023-12-18 15:22:46 -08:00
hasAutoConvertEmoji: true,
hasAutoDownloadUpdate: true,
hasAutoLaunch: true,
hasCallNotifications: true,
hasCallRingtoneNotification: false,
hasCountMutedConversations: false,
hasHideMenuBar: false,
hasIncomingCallNotifications: true,
hasLinkPreviews: true,
hasMediaCameraPermissions: true,
hasMediaPermissions: true,
hasMessageAudio: true,
hasMinimizeToAndStartInSystemTray: true,
hasMinimizeToSystemTray: true,
hasNotificationAttention: false,
hasNotifications: true,
hasReadReceipts: true,
hasRelayCalls: false,
hasSpellCheck: true,
hasStoriesDisabled: false,
hasTextFormatting: true,
hasTypingIndicators: true,
initialSpellCheckSetting: true,
isAutoDownloadUpdatesSupported: true,
isAutoLaunchSupported: true,
isHideMenuBarSupported: true,
isNotificationAttentionSupported: true,
isSyncSupported: true,
isSystemTraySupported: true,
2025-04-15 16:04:30 -07:00
isInternalUser: false,
isMinimizeToAndStartInSystemTraySupported: true,
lastSyncTime: Date.now(),
2023-11-06 13:19:23 -08:00
localeOverride: null,
notificationContent: 'name',
2023-11-06 13:19:23 -08:00
preferredSystemLocales: ['en'],
resolvedLocale: 'en',
selectedCamera:
'dfbe6effe70b0611ba0fdc2a9ea3f39f6cb110e6687948f7e5f016c111b7329c',
selectedMicrophone: availableMicrophones[0],
selectedSpeaker: availableSpeakers[1],
sentMediaQualitySetting: 'standard',
themeSetting: 'system',
universalExpireTimer: DurationInSeconds.HOUR,
whoCanFindMe: PhoneNumberDiscoverability.Discoverable,
whoCanSeeMe: PhoneNumberSharingMode.Everybody,
zoomFactor: 1,
getConversationsWithCustomColor: () => Promise.resolve([]),
addCustomColor: action('addCustomColor'),
closeSettings: action('closeSettings'),
doDeleteAllData: action('doDeleteAllData'),
doneRendering: action('doneRendering'),
editCustomColor: action('editCustomColor'),
makeSyncRequest: action('makeSyncRequest'),
onAudioNotificationsChange: action('onAudioNotificationsChange'),
2023-12-18 15:22:46 -08:00
onAutoConvertEmojiChange: action('onAutoConvertEmojiChange'),
onAutoDownloadAttachmentChange: action('onAutoDownloadAttachmentChange'),
onAutoDownloadUpdateChange: action('onAutoDownloadUpdateChange'),
onAutoLaunchChange: action('onAutoLaunchChange'),
onCallNotificationsChange: action('onCallNotificationsChange'),
onCallRingtoneNotificationChange: action(
'onCallRingtoneNotificationChange'
),
onCountMutedConversationsChange: action('onCountMutedConversationsChange'),
2025-03-26 12:35:32 -07:00
onEmojiSkinToneDefaultChange: action('onEmojiSkinToneDefaultChange'),
onHasStoriesDisabledChanged: action('onHasStoriesDisabledChanged'),
onHideMenuBarChange: action('onHideMenuBarChange'),
onIncomingCallNotificationsChange: action(
'onIncomingCallNotificationsChange'
),
2023-11-06 13:19:23 -08:00
onLocaleChange: action('onLocaleChange'),
onLastSyncTimeChange: action('onLastSyncTimeChange'),
onMediaCameraPermissionsChange: action('onMediaCameraPermissionsChange'),
onMediaPermissionsChange: action('onMediaPermissionsChange'),
onMessageAudioChange: action('onMessageAudioChange'),
onMinimizeToAndStartInSystemTrayChange: action(
'onMinimizeToAndStartInSystemTrayChange'
),
onMinimizeToSystemTrayChange: action('onMinimizeToSystemTrayChange'),
onNotificationAttentionChange: action('onNotificationAttentionChange'),
onNotificationContentChange: action('onNotificationContentChange'),
onNotificationsChange: action('onNotificationsChange'),
onRelayCallsChange: action('onRelayCallsChange'),
onSelectedCameraChange: action('onSelectedCameraChange'),
onSelectedMicrophoneChange: action('onSelectedMicrophoneChange'),
onSelectedSpeakerChange: action('onSelectedSpeakerChange'),
onSentMediaQualityChange: action('onSentMediaQualityChange'),
onSpellCheckChange: action('onSpellCheckChange'),
onTextFormattingChange: action('onTextFormattingChange'),
onThemeChange: action('onThemeChange'),
onUniversalExpireTimerChange: action('onUniversalExpireTimerChange'),
onWhoCanSeeMeChange: action('onWhoCanSeeMeChange'),
onWhoCanFindMeChange: action('onWhoCanFindMeChange'),
onZoomFactorChange: action('onZoomFactorChange'),
2025-04-02 14:57:29 -04:00
refreshCloudBackupStatus: action('refreshCloudBackupStatus'),
refreshBackupSubscriptionStatus: action('refreshBackupSubscriptionStatus'),
removeCustomColor: action('removeCustomColor'),
removeCustomColorOnConversations: action(
'removeCustomColorOnConversations'
),
resetAllChatColors: action('resetAllChatColors'),
resetDefaultChatColor: action('resetDefaultChatColor'),
setGlobalDefaultConversationColor: action(
'setGlobalDefaultConversationColor'
),
2025-04-15 16:04:30 -07:00
validateBackup: async () => {
return {
result: {
totalBytes: 100,
2025-04-24 14:53:42 -07:00
duration: 10000,
stats: {
adHocCalls: 1,
callLinks: 2,
conversations: 3,
chats: 4,
distributionLists: 5,
messages: 6,
notificationProfiles: 2,
skippedMessages: 7,
stickerPacks: 8,
fixedDirectMessages: 9,
},
2025-04-15 16:04:30 -07:00
},
};
},
} satisfies PropsType,
} satisfies Meta<PropsType>;
2021-08-18 16:08:14 -04:00
2022-11-17 16:45:19 -08:00
// eslint-disable-next-line react/function-component-definition
const Template: StoryFn<PropsType> = args => <Preferences {...args} />;
2021-08-18 16:08:14 -04:00
2022-07-19 20:47:05 -04:00
export const _Preferences = Template.bind({});
2021-08-18 16:08:14 -04:00
2022-07-19 20:47:05 -04:00
export const Blocked1 = Template.bind({});
Blocked1.args = {
blockedCount: 1,
};
2021-08-18 16:08:14 -04:00
2022-07-19 20:47:05 -04:00
export const BlockedMany = Template.bind({});
BlockedMany.args = {
blockedCount: 55,
};
2022-06-06 20:48:02 -04:00
2022-07-19 20:47:05 -04:00
export const CustomUniversalExpireTimer = Template.bind({});
CustomUniversalExpireTimer.args = {
2022-11-16 12:18:02 -08:00
universalExpireTimer: DurationInSeconds.fromSeconds(9000),
2022-07-19 20:47:05 -04:00
};
2023-02-23 13:32:19 -08:00
export const PNPSharingDisabled = Template.bind({});
PNPSharingDisabled.args = {
whoCanSeeMe: PhoneNumberSharingMode.Nobody,
whoCanFindMe: PhoneNumberDiscoverability.Discoverable,
};
export const PNPDiscoverabilityDisabled = Template.bind({});
PNPDiscoverabilityDisabled.args = {
whoCanSeeMe: PhoneNumberSharingMode.Nobody,
whoCanFindMe: PhoneNumberDiscoverability.NotDiscoverable,
};
2025-04-02 14:57:29 -04:00
export const BackupsPaidActive = Template.bind({});
BackupsPaidActive.args = {
initialPage: Page.Backups,
backupFeatureEnabled: true,
cloudBackupStatus: {
mediaSize: 539_249_410_039,
protoSize: 100_000_000,
createdAt: new Date(Date.now() - WEEK).getTime(),
},
backupSubscriptionStatus: {
status: 'active',
cost: {
amount: 22.99,
currencyCode: 'USD',
},
renewalDate: new Date(Date.now() + 20 * DAY),
},
};
export const BackupsPaidCancelled = Template.bind({});
BackupsPaidCancelled.args = {
initialPage: Page.Backups,
backupFeatureEnabled: true,
cloudBackupStatus: {
mediaSize: 539_249_410_039,
protoSize: 100_000_000,
createdAt: new Date(Date.now() - WEEK).getTime(),
},
backupSubscriptionStatus: {
status: 'pending-cancellation',
cost: {
amount: 22.99,
currencyCode: 'USD',
},
expiryDate: new Date(Date.now() + 20 * DAY),
},
};
export const BackupsFree = Template.bind({});
BackupsFree.args = {
initialPage: Page.Backups,
backupFeatureEnabled: true,
backupSubscriptionStatus: {
status: 'free',
mediaIncludedInBackupDurationDays: 30,
},
};
export const BackupsOff = Template.bind({});
BackupsOff.args = {
initialPage: Page.Backups,
backupFeatureEnabled: true,
};
export const BackupsSubscriptionNotFound = Template.bind({});
BackupsSubscriptionNotFound.args = {
initialPage: Page.Backups,
backupFeatureEnabled: true,
backupSubscriptionStatus: {
status: 'not-found',
},
cloudBackupStatus: {
mediaSize: 539_249_410_039,
protoSize: 100_000_000,
createdAt: new Date(Date.now() - WEEK).getTime(),
},
};
export const BackupsSubscriptionExpired = Template.bind({});
BackupsSubscriptionExpired.args = {
initialPage: Page.Backups,
backupFeatureEnabled: true,
backupSubscriptionStatus: {
status: 'expired',
},
};
2025-04-15 16:04:30 -07:00
export const Internal = Template.bind({});
Internal.args = {
initialPage: Page.Internal,
isInternalUser: true,
};