throw error properly when changing various settings
This commit is contained in:
parent
4da96b68f1
commit
88bb27c0d1
8 changed files with 38 additions and 9 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import React, { useCallback, useMemo } from 'react';
|
||||
import { putStateEvent } from 'neurone/lib/api/matrix/client/v3/rooms';
|
||||
import { parseMatrixResp } from 'neurone/lib/matrix-request';
|
||||
import { usePowerLevelsContext } from '../../hooks/usePowerLevels';
|
||||
import { ImagePackContent } from './ImagePackContent';
|
||||
import { ImagePack, PackContent } from '../../plugins/custom-emoji';
|
||||
|
|
@ -43,7 +44,7 @@ export function RoomImagePack({ roomId, stateKey }: RoomImagePackProps) {
|
|||
const { address } = imagePack;
|
||||
if (!address) return;
|
||||
|
||||
await ct.requestAuthJSON(
|
||||
const resp = await ct.requestAuthJSON(
|
||||
putStateEvent({
|
||||
pathParams: {
|
||||
roomId: address.roomId,
|
||||
|
|
@ -53,6 +54,8 @@ export function RoomImagePack({ roomId, stateKey }: RoomImagePackProps) {
|
|||
body: packContent,
|
||||
})
|
||||
);
|
||||
const [err] = await parseMatrixResp(resp);
|
||||
if (err) throw new Error(err.data.error ?? err.data.errcode);
|
||||
},
|
||||
[ct, imagePack]
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import React, { useCallback, useMemo } from 'react';
|
||||
import { putAccountData } from 'neurone/lib/api/matrix/client/v3/user';
|
||||
import { parseMatrixResp } from 'neurone/lib/matrix-request';
|
||||
import { ImagePackContent } from './ImagePackContent';
|
||||
import { ImagePack, PackContent } from '../../plugins/custom-emoji';
|
||||
import { AccountDataType } from '../../../types/matrix/accountData';
|
||||
|
|
@ -15,12 +16,14 @@ export function UserImagePack() {
|
|||
|
||||
const handleUpdate = useCallback(
|
||||
async (packContent: PackContent) => {
|
||||
await ct.requestAuthJSON(
|
||||
const resp = await ct.requestAuthJSON(
|
||||
putAccountData({
|
||||
pathParams: { type: AccountDataType.PoniesUserEmotes, userId: ct.session.userId },
|
||||
body: packContent,
|
||||
})
|
||||
);
|
||||
const [err] = await parseMatrixResp(resp);
|
||||
if (err) throw new Error(err.data.error ?? err.data.errcode);
|
||||
},
|
||||
[ct]
|
||||
);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import {
|
|||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { postInvite } from 'neurone/lib/api/matrix/client/v3/rooms';
|
||||
import { parseMatrixResp } from 'neurone/lib/matrix-request';
|
||||
import { stopPropagation } from '../../utils/keyboard';
|
||||
import { useDirectUsers } from '../../hooks/useDirectUsers';
|
||||
import { getMxIdLocalPart, getMxIdServer, isUserId } from '../../utils/matrix';
|
||||
|
|
@ -73,7 +74,7 @@ export function InviteUserPrompt({ roomId, requestClose }: InviteUserProps) {
|
|||
const [inviteState, invite] = useAsyncCallback<void, Error, [string, string | undefined]>(
|
||||
useCallback(
|
||||
async (userId, reason) => {
|
||||
await ct.requestAuthJSON(
|
||||
const resp = await ct.requestAuthJSON(
|
||||
postInvite({
|
||||
pathParams: { roomId },
|
||||
body: {
|
||||
|
|
@ -82,6 +83,8 @@ export function InviteUserPrompt({ roomId, requestClose }: InviteUserProps) {
|
|||
},
|
||||
})
|
||||
);
|
||||
const [err] = await parseMatrixResp(resp);
|
||||
if (err) throw new Error(err.data.error ?? err.data.errcode);
|
||||
},
|
||||
[ct, roomId]
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|||
import { Badge, Box, Button, Chip, config, Icon, Icons, Menu, Spinner, Text } from 'folds';
|
||||
import produce from 'immer';
|
||||
import { putStateEvent } from 'neurone/lib/api/matrix/client/v3/rooms';
|
||||
import { parseMatrixResp } from 'neurone/lib/matrix-request';
|
||||
import { SequenceCard } from '../../../components/sequence-card';
|
||||
import { SequenceCardStyle } from '../styles.css';
|
||||
import { SettingTile } from '../../../components/setting-tile';
|
||||
|
|
@ -86,12 +87,14 @@ export function PermissionGroups({ permissionGroups, canEdit }: PermissionGroups
|
|||
|
||||
return draftPowerLevels;
|
||||
});
|
||||
await ct.requestAuthJSON(
|
||||
const resp = await ct.requestAuthJSON(
|
||||
putStateEvent({
|
||||
pathParams: { roomId, eventType: StateEventType.RoomPowerLevels, stateKey: '' },
|
||||
body: editedPowerLevels,
|
||||
})
|
||||
);
|
||||
const [err] = await parseMatrixResp(resp);
|
||||
if (err) throw new Error(err.data.error ?? err.data.errcode);
|
||||
}, [ct, roomId, powerLevels, permissionUpdate, permissionGroups])
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import {
|
|||
} from 'folds';
|
||||
import { HexColorPicker } from 'react-colorful';
|
||||
import { putStateEvent } from 'neurone/lib/api/matrix/client/v3/rooms';
|
||||
import { parseMatrixResp } from 'neurone/lib/matrix-request';
|
||||
import { Page, PageContent, PageHeader } from '../../../components/page';
|
||||
import { usePowerLevelsContext } from '../../../hooks/usePowerLevels';
|
||||
import { SequenceCard } from '../../../components/sequence-card';
|
||||
|
|
@ -333,12 +334,14 @@ export function PowersEditor({ requestClose }: PowersEditorProps) {
|
|||
deleted.forEach((power) => {
|
||||
delete content[power];
|
||||
});
|
||||
await ct.requestAuthJSON(
|
||||
const resp = await ct.requestAuthJSON(
|
||||
putStateEvent({
|
||||
pathParams: { roomId, eventType: StateEventType.PowerLevelTags, stateKey: '' },
|
||||
body: content,
|
||||
})
|
||||
);
|
||||
const [err] = await parseMatrixResp(resp);
|
||||
if (err) throw new Error(err.data.error ?? err.data.errcode);
|
||||
}, [ct, roomId, powerLevelTags, editedPowerTags, deleted])
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import React, { useCallback, useMemo } from 'react';
|
|||
import { Badge, Box, Text } from 'folds';
|
||||
import { PushRuleCondition, PushRules } from 'neurone/lib/api/types';
|
||||
import { putPushRuleActions } from 'neurone/lib/api/matrix/client/v3/pushrules';
|
||||
import { parseMatrixResp } from 'neurone/lib/matrix-request';
|
||||
import { AccountDataType, ConditionKind, PushRuleId } from '../../../../types/matrix/accountData';
|
||||
import { NotificationModeSwitcher } from './NotificationModeSwitcher';
|
||||
import { SequenceCard } from '../../../components/sequence-card';
|
||||
|
|
@ -65,12 +66,14 @@ function AllMessagesModeSwitcher({
|
|||
const handleChange = useCallback(
|
||||
async (mode: NotificationMode) => {
|
||||
const actions = getModeActions(mode);
|
||||
await ct.requestAuthJSON(
|
||||
const resp = await ct.requestAuthJSON(
|
||||
putPushRuleActions({
|
||||
pathParams: { scope: 'global', kind, ruleId },
|
||||
body: { actions },
|
||||
})
|
||||
);
|
||||
const [err] = await parseMatrixResp(resp);
|
||||
if (err) throw new Error(err.data.error ?? err.data.errcode);
|
||||
},
|
||||
[ct, getModeActions, kind, ruleId]
|
||||
);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {
|
|||
putPushRule,
|
||||
putPushRuleActions,
|
||||
} from 'neurone/lib/api/matrix/client/v3/pushrules';
|
||||
import { parseMatrixResp } from 'neurone/lib/matrix-request';
|
||||
import { PushRule, PushRules } from 'neurone/lib/api/types';
|
||||
import { useAccountData } from '../../../hooks/storage/useAccountData';
|
||||
import { AccountDataType } from '../../../../types/matrix/accountData';
|
||||
|
|
@ -32,7 +33,7 @@ function KeywordInput() {
|
|||
const [keywordState, addKeyword] = useAsyncCallback(
|
||||
useCallback(
|
||||
async (k: string) => {
|
||||
await ct.requestAuthJSON(
|
||||
const resp = await ct.requestAuthJSON(
|
||||
putPushRule({
|
||||
pathParams: { scope: 'global', kind: 'content', ruleId: k },
|
||||
body: {
|
||||
|
|
@ -41,6 +42,9 @@ function KeywordInput() {
|
|||
},
|
||||
})
|
||||
);
|
||||
|
||||
const [err] = await parseMatrixResp(resp);
|
||||
if (err) throw new Error(err.data.error ?? err.data.errcode);
|
||||
setKeyword('');
|
||||
},
|
||||
[ct]
|
||||
|
|
@ -147,7 +151,7 @@ function KeywordModeSwitcher({ pushRule }: PushRulesProps) {
|
|||
const handleChange = useCallback(
|
||||
async (mode: NotificationMode) => {
|
||||
const actions = getModeActions(mode);
|
||||
await ct.requestAuthJSON(
|
||||
const resp = await ct.requestAuthJSON(
|
||||
putPushRuleActions({
|
||||
pathParams: { scope: 'global', kind: 'content', ruleId: pushRule.rule_id },
|
||||
body: {
|
||||
|
|
@ -155,6 +159,9 @@ function KeywordModeSwitcher({ pushRule }: PushRulesProps) {
|
|||
},
|
||||
})
|
||||
);
|
||||
|
||||
const [err] = await parseMatrixResp(resp);
|
||||
if (err) throw new Error(err.data.error ?? err.data.errcode);
|
||||
},
|
||||
[ct, getModeActions, pushRule]
|
||||
);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import React, { useCallback, useMemo } from 'react';
|
|||
import { Box, Text, Badge } from 'folds';
|
||||
import { PushRules } from 'neurone/lib/api/types';
|
||||
import { putPushRuleActions } from 'neurone/lib/api/matrix/client/v3/pushrules';
|
||||
import { parseMatrixResp } from 'neurone/lib/matrix-request';
|
||||
import { useAccountData } from '../../../hooks/storage/useAccountData';
|
||||
import { AccountDataType, ConditionKind, PushRuleId } from '../../../../types/matrix/accountData';
|
||||
import { SequenceCard } from '../../../components/sequence-card';
|
||||
|
|
@ -104,12 +105,15 @@ function MentionModeSwitcher({ ruleId, pushRules, defaultPushRuleData }: PushRul
|
|||
const handleChange = useCallback(
|
||||
async (mode: NotificationMode) => {
|
||||
const actions = getModeActions(mode);
|
||||
await ct.requestAuthJSON(
|
||||
const resp = await ct.requestAuthJSON(
|
||||
putPushRuleActions({
|
||||
pathParams: { scope: 'global', kind, ruleId },
|
||||
body: { actions },
|
||||
})
|
||||
);
|
||||
|
||||
const [err] = await parseMatrixResp(resp);
|
||||
if (err) throw new Error(err.data.error ?? err.data.errcode);
|
||||
},
|
||||
[ct, getModeActions, kind, ruleId]
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue