Skip to content

Commit

Permalink
feat(web): 增加配置项不发送输入状态
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed May 8, 2020
1 parent 18c66a6 commit fca42b6
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 16 deletions.
9 changes: 9 additions & 0 deletions src/shared/api/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import _throttle from 'lodash/throttle';
import config from '@shared/project.config';
import { ConverseType } from '@redux/types/chat';
import * as trpgApi from './trpg.api';
import { getSystemSettings } from '@redux/helpers/settings';
const api = trpgApi.getInstance();

/**
* 发送开始写
*/
export const sendStartWriting = _throttle(
(type: ConverseType = 'user', uuid: string, currentText?: string) => {
if (getSystemSettings<boolean>('disableSendWritingState', false) === true) {
return;
}

return api.emit('chat::startWriting', { type, uuid, currentText });
},
config.chat.isWriting.throttle,
Expand All @@ -20,6 +25,10 @@ export const sendStartWriting = _throttle(
*/
export const sendStopWriting = _throttle(
(type: ConverseType = 'user', uuid: string) => {
if (getSystemSettings<boolean>('disableSendWritingState', false) === true) {
return;
}

return api.emit('chat::stopWriting', { type, uuid });
},
config.chat.isWriting.throttle,
Expand Down
29 changes: 17 additions & 12 deletions src/shared/project.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,24 @@ interface ProjectConfig {
blog: string;
portal: string;
};
defaultSettings: {
user: {};
system: {};
};
defaultSettings: DefaultSettings;
}

/**
* 默认设置
*/
const defaultSettings = {
user: {
favoriteDice: [],
},
system: {
notification: true,
disableSendWritingState: false,
},
};

export type DefaultSettings = typeof defaultSettings;

const config: ProjectConfig = {
version: require('../../package.json').version,
environment,
Expand Down Expand Up @@ -210,14 +222,7 @@ const config: ProjectConfig = {
blog: 'https://trpgdoc.moonrailgun.com/blog/',
portal: portalUrl,
},
defaultSettings: {
user: {
favoriteDice: [],
},
system: {
notification: true,
},
},
defaultSettings,
};
config.file.url = `${config.file.protocol}://${config.file.host}:${config.file.port}`;
config.url.api = config.file.url;
Expand Down
27 changes: 27 additions & 0 deletions src/shared/redux/helpers/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getStoreState } from '@redux/configureStore/helper';
import { SettingType } from '@redux/types/settings';
import _get from 'lodash/get';

/**
* 获取用户设置
*/
export function getUserSettings<T extends SettingType>(
field: string,
defaultValue: T
): T {
const state = getStoreState();

return (_get(state, ['settings', 'user', field]) as T) ?? defaultValue;
}

/**
* 获取系统设置
*/
export function getSystemSettings<T extends SettingType>(
field: string,
defaultValue: T
): T {
const state = getStoreState();

return (_get(state, ['settings', 'system', field]) as T) ?? defaultValue;
}
14 changes: 10 additions & 4 deletions src/shared/redux/types/settings.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { DefaultSettings } from '@shared/project.config';

type NotificationType = 'granted' | 'denied' | 'default';

export interface ServerConfig {
[name: string]: string | boolean | number | string[];
export type SettingType = string | boolean | number | string[];

interface CustomConfig {
[name: string]: SettingType;
}

export type ServerConfig = CustomConfig;

export interface SettingsState {
user: any;
system: any;
user: DefaultSettings['user'] & CustomConfig;
system: DefaultSettings['system'] & CustomConfig;
notificationPermission: NotificationType;
config: ServerConfig; // 服务端配置
}
14 changes: 14 additions & 0 deletions src/web/components/modal/SystemSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ const SystemSettings: React.FC = TMemo(() => {
[dispatch]
);

const handleSetDisableSendWritingState = useCallback(
(isChecked: boolean) => {
dispatch(setSystemSettings({ disableSendWritingState: isChecked }));
},
[dispatch]
);

return (
<ModalPanel title="系统设置">
<SettingCell>
Expand All @@ -48,6 +55,13 @@ const SystemSettings: React.FC = TMemo(() => {
onChange={handleRequestNotificationPermission}
/>
</SettingCell>
<SettingCell>
<label>不发送输入状态</label>
<Checkbox
value={systemSettings.disableSendWritingState}
onChange={handleSetDisableSendWritingState}
/>
</SettingCell>
<SettingCell>
<label>是否为内测用户</label>
<Checkbox value={isAlphaUser} onChange={setIsAlphaUser} />
Expand Down

0 comments on commit fca42b6

Please sign in to comment.