git ssb

1+

Daan Patchwork / manyverse



Commit 8eb373edc099d611e4324a1c3e6513aac8e2b9b7

dx: show toast when recipients-input max is reached

Andre Staltz committed on 2/4/2020, 11:52:48 AM
Parent: e580857ce50d54c154e7fabd8bfb38f77620b354

Files changed

src/frontend/components/AccountsListCheckMany.tschanged
src/frontend/screens/conversation/ssb.tschanged
src/frontend/screens/recipients-input/index.tschanged
src/frontend/screens/recipients-input/intent.tschanged
src/frontend/screens/recipients-input/model.tschanged
src/frontend/screens/recipients-input/view.tschanged
src/frontend/ssb/utils/constants.tsadded
src/frontend/components/AccountsListCheckMany.tsView
@@ -123,8 +123,9 @@
123123
124124 export type Props = {
125125 accounts: Array<{name: string; imageUrl: string; id: string}>;
126126 onUpdated?: (ev: Props['accounts']) => void;
127+ onMaxReached?: () => void;
127128 maximumCheckable?: number;
128129 };
129130
130131 type State = {
@@ -180,8 +181,10 @@
180181 } else if (checked.length < max) {
181182 const newChecked = checked.concat([account]);
182183 this.setState({checked: newChecked});
183184 onUpdated?.(newChecked);
185+ } else {
186+ this.props.onMaxReached?.();
184187 }
185188 },
186189 });
187190 }),
src/frontend/screens/conversation/ssb.tsView
@@ -9,8 +9,9 @@
99 import {toReplyPostContent, toPostContent} from '../../ssb/utils/to-ssb';
1010 import {State} from './model';
1111 import {Req, contentToPublishReq} from '../../drivers/ssb';
1212 import {PostContent} from 'ssb-typescript';
13+import {MAX_PRIVATE_MESSAGE_RECIPIENTS} from '../../ssb/utils/constants';
1314
1415 export type SSBActions = {
1516 publishMsg$: Stream<string>;
1617 };
@@ -26,10 +27,14 @@
2627 function createRootContent(text: string, state: State): PostContent {
2728 if (state.thread.recps.length === 0) {
2829 throw new Error('Cannot publish new conversation without recipients');
2930 }
30- if (state.thread.recps.length > 7) {
31- throw new Error('Cannot publish conversation with more than 7 recipients');
31+ if (state.thread.recps.length > MAX_PRIVATE_MESSAGE_RECIPIENTS) {
32+ throw new Error(
33+ 'Cannot publish conversation with more than ' +
34+ MAX_PRIVATE_MESSAGE_RECIPIENTS +
35+ ' recipients',
36+ );
3237 }
3338 const content = toPostContent(text);
3439 content.recps = state.thread.recps.map(recp => recp.id);
3540 if (!content.recps.includes(state.selfFeedId)) {
src/frontend/screens/recipients-input/index.tsView
@@ -9,15 +9,17 @@
99 import {ReactElement} from 'react';
1010 import {ReactSource} from '@cycle/react';
1111 import isolate from '@cycle/isolate';
1212 import {StateSource, Reducer} from '@cycle/state';
13+import {FeedId} from 'ssb-typescript';
1314 import {SSBSource} from '../../drivers/ssb';
15+import {Toast, Duration} from '../../drivers/toast';
1416 import {topBar, Sinks as TBSinks} from './top-bar';
1517 import model, {State, topBarLens} from './model';
1618 import view from './view';
1719 import intent from './intent';
1820 import navigation from './navigation';
19-import {FeedId} from 'ssb-typescript';
21+import {MAX_PRIVATE_MESSAGE_RECIPIENTS} from '../../ssb/utils/constants';
2022
2123 export type Props = {
2224 selfFeedId: FeedId;
2325 };
@@ -33,8 +35,9 @@
3335 export type Sinks = {
3436 screen: Stream<ReactElement<any>>;
3537 navigation: Stream<Command>;
3638 state: Stream<Reducer<State>>;
39+ toast: Stream<Toast>;
3740 };
3841
3942 export const navOptions = {
4043 topBar: {
@@ -63,11 +66,20 @@
6366 topBarSinks.next,
6467 );
6568 const reducer$ = model(sources.props, sources.ssb, actions);
6669 const command$ = navigation(actions, state$);
70+ const toast$ = actions.maxReached$.mapTo({
71+ type: 'show',
72+ message:
73+ 'Cannot choose more than ' +
74+ MAX_PRIVATE_MESSAGE_RECIPIENTS +
75+ ' recipients',
76+ duration: Duration.LONG,
77+ } as Toast);
6778
6879 return {
6980 screen: vdom$,
7081 navigation: command$,
82+ toast: toast$,
7183 state: reducer$,
7284 };
7385 }
src/frontend/screens/recipients-input/intent.tsView
@@ -23,8 +23,12 @@
2323 updateRecipients$: reactSource
2424 .select('recipients')
2525 .events('updated') as Stream<PrivateThreadAndExtras['recps']>,
2626
27+ maxReached$: reactSource
28+ .select('recipients')
29+ .events('maxReached') as Stream<undefined>,
30+
2731 goBack$: xs.merge(navSource.backPress(), topBarBack$) as Stream<null>,
2832
2933 goToNewConversation$: topBarNext$,
3034 };
src/frontend/screens/recipients-input/model.tsView
@@ -13,8 +13,9 @@
1313 import {FeedId} from 'ssb-typescript';
1414 import {Lens} from '@cycle/state';
1515 import {State as TopBarState} from './top-bar';
1616 import {Props} from '.';
17+import {MAX_PRIVATE_MESSAGE_RECIPIENTS} from '../../ssb/utils/constants';
1718
1819 export type State = {
1920 selfFeedId: FeedId;
2021 mentionQuery: string;
@@ -29,9 +30,11 @@
2930
3031 export const topBarLens: Lens<State, TopBarState> = {
3132 get: (parent: State): TopBarState => {
3233 return {
33- enabled: 0 < parent.recipients.length && parent.recipients.length <= 7,
34+ enabled:
35+ 0 < parent.recipients.length &&
36+ parent.recipients.length <= MAX_PRIVATE_MESSAGE_RECIPIENTS,
3437 };
3538 },
3639
3740 // Ignore writes from the child
src/frontend/screens/recipients-input/view.tsView
@@ -4,18 +4,19 @@
44 * License, v. 2.0. If a copy of the MPL was not distributed with this
55 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
66
77 import xs, {Stream} from 'xstream';
8-import {State} from './model';
8+import {ReactElement} from 'react';
99 import {h} from '@cycle/react';
1010 import {View, TextInput, ScrollView} from 'react-native';
1111 import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
1212 import {Dimensions} from '../../global-styles/dimens';
1313 import {Palette} from '../../global-styles/palette';
14-import {styles} from './styles';
15-import {ReactElement} from 'react';
1614 import EmptySection from '../../components/EmptySection';
1715 import AccountsListCheckMany from '../../components/AccountsListCheckMany';
16+import {MAX_PRIVATE_MESSAGE_RECIPIENTS} from '../../ssb/utils/constants';
17+import {State} from './model';
18+import {styles} from './styles';
1819
1920 export default function view(
2021 state$: Stream<State>,
2122 topBar$: Stream<ReactElement<any>>,
@@ -50,9 +51,9 @@
5051 [
5152 h(AccountsListCheckMany, {
5253 sel: 'recipients',
5354 accounts: state.mentionSuggestions as any,
54- maximumCheckable: 7,
55+ maximumCheckable: MAX_PRIVATE_MESSAGE_RECIPIENTS,
5556 }),
5657 state.mentionSuggestions.length
5758 ? null
5859 : h(EmptySection, {
src/frontend/ssb/utils/constants.tsView
@@ -1,0 +1,12 @@
1+/* Copyright (C) 2020 The Manyverse Authors.
2+ *
3+ * This Source Code Form is subject to the terms of the Mozilla Public
4+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6+
7+/**
8+ * For compatibility with Patchwork, we select the same (arbitrary!) limit of
9+ * PM recipients, which is 8 (including the selfId!). For practical purposes in
10+ * the app we think in terms of *other* recipients, so 8 - 1 = 7.
11+ */
12+export const MAX_PRIVATE_MESSAGE_RECIPIENTS = 7;

Built with git-ssb-web