From 5720d396fce21b7698e3dd884346f2d0e3c674f5 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 30 Mar 2023 20:41:44 -0500 Subject: [PATCH] Groups: make "share with followers" button work --- app/soapbox/actions/compose.ts | 14 ++++++++- .../compose/components/compose-form.tsx | 5 +++- app/soapbox/features/group/group-timeline.tsx | 30 ++++++++++++++----- app/soapbox/reducers/compose.ts | 4 +++ 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/app/soapbox/actions/compose.ts b/app/soapbox/actions/compose.ts index 8be60bfc75..995f37c151 100644 --- a/app/soapbox/actions/compose.ts +++ b/app/soapbox/actions/compose.ts @@ -48,6 +48,7 @@ const COMPOSE_UPLOAD_FAIL = 'COMPOSE_UPLOAD_FAIL'; const COMPOSE_UPLOAD_PROGRESS = 'COMPOSE_UPLOAD_PROGRESS'; const COMPOSE_UPLOAD_UNDO = 'COMPOSE_UPLOAD_UNDO'; const COMPOSE_GROUP_POST = 'COMPOSE_GROUP_POST'; +const COMPOSE_SET_GROUP_TIMELINE_VISIBLE = 'COMPOSE_SET_GROUP_TIMELINE_VISIBLE'; const COMPOSE_SUGGESTIONS_CLEAR = 'COMPOSE_SUGGESTIONS_CLEAR'; const COMPOSE_SUGGESTIONS_READY = 'COMPOSE_SUGGESTIONS_READY'; @@ -292,7 +293,10 @@ const submitCompose = (composeId: string, routerHistory?: History, force = false to, }; - if (compose.privacy === 'group') params.group_id = compose.group_id; + if (compose.privacy === 'group') { + params.group_id = compose.group_id; + params.group_timeline_visible = compose.group_timeline_visible; // Truth Social + } dispatch(createStatus(params, idempotencyKey, statusId)).then(function(data) { if (!statusId && data.visibility === 'direct' && getState().conversations.mounted <= 0 && routerHistory) { @@ -483,6 +487,12 @@ const groupCompose = (composeId: string, groupId: string) => }); }; +const setGroupTimelineVisible = (composeId: string, groupTimelineVisible: boolean) => ({ + type: COMPOSE_SET_GROUP_TIMELINE_VISIBLE, + id: composeId, + groupTimelineVisible, +}); + const clearComposeSuggestions = (composeId: string) => { if (cancelFetchComposeSuggestionsAccounts) { cancelFetchComposeSuggestionsAccounts(); @@ -792,6 +802,7 @@ export { COMPOSE_ADD_TO_MENTIONS, COMPOSE_REMOVE_FROM_MENTIONS, COMPOSE_SET_STATUS, + COMPOSE_SET_GROUP_TIMELINE_VISIBLE, setComposeToStatus, changeCompose, replyCompose, @@ -818,6 +829,7 @@ export { uploadComposeFail, undoUploadCompose, groupCompose, + setGroupTimelineVisible, clearComposeSuggestions, fetchComposeSuggestions, readyComposeSuggestionsEmojis, diff --git a/app/soapbox/features/compose/components/compose-form.tsx b/app/soapbox/features/compose/components/compose-form.tsx index 00167886f1..321b30aa2e 100644 --- a/app/soapbox/features/compose/components/compose-form.tsx +++ b/app/soapbox/features/compose/components/compose-form.tsx @@ -63,9 +63,10 @@ interface IComposeForm { clickableAreaRef?: React.RefObject event?: string group?: string + extra?: React.ReactNode } -const ComposeForm = ({ id, shouldCondense, autoFocus, clickableAreaRef, event, group }: IComposeForm) => { +const ComposeForm = ({ id, shouldCondense, autoFocus, clickableAreaRef, event, group, extra }: IComposeForm) => { const history = useHistory(); const intl = useIntl(); const dispatch = useAppDispatch(); @@ -333,6 +334,8 @@ const ComposeForm = ({ id, shouldCondense, autoFocus, clickab + {extra &&
{extra}
} +
= (props) => { const { group } = useGroup(groupId); + const composeId = `group:${groupId}`; const canComposeGroupStatus = !!account && group?.relationship?.member; + const groupTimelineVisible = useAppSelector((state) => !!state.compose.get(composeId)?.group_timeline_visible); const handleLoadMore = (maxId: string) => { dispatch(expandGroupTimeline(groupId, { maxId })); }; + const handleToggleChange = () => { + dispatch(setGroupTimelineVisible(composeId, !groupTimelineVisible)); + }; + useEffect(() => { dispatch(expandGroupTimeline(groupId)); - - dispatch(groupCompose(`group:${groupId}`, groupId)); + dispatch(groupCompose(composeId, groupId)); const disconnect = dispatch(connectGroupStream(groupId)); @@ -58,10 +63,21 @@ const GroupTimeline: React.FC = (props) => { +
+ Share with my followers +
+ + + )} />
@@ -69,7 +85,7 @@ const GroupTimeline: React.FC = (props) => { diff --git a/app/soapbox/reducers/compose.ts b/app/soapbox/reducers/compose.ts index 63bec8be6b..cfce14a5ad 100644 --- a/app/soapbox/reducers/compose.ts +++ b/app/soapbox/reducers/compose.ts @@ -51,6 +51,7 @@ import { COMPOSE_REMOVE_FROM_MENTIONS, COMPOSE_SET_STATUS, COMPOSE_EVENT_REPLY, + COMPOSE_SET_GROUP_TIMELINE_VISIBLE, } from '../actions/compose'; import { ME_FETCH_SUCCESS, ME_PATCH_SUCCESS } from '../actions/me'; import { SETTING_CHANGE, FE_NAME } from '../actions/settings'; @@ -103,6 +104,7 @@ export const ReducerCompose = ImmutableRecord({ tagHistory: ImmutableList(), text: '', to: ImmutableOrderedSet(), + group_timeline_visible: false, // TruthSocial }); type State = ImmutableMap; @@ -493,6 +495,8 @@ export default function compose(state = initialState, action: AnyAction) { return updateCompose(state, action.id, compose => compose.update('to', mentions => mentions!.add(action.account))); case COMPOSE_REMOVE_FROM_MENTIONS: return updateCompose(state, action.id, compose => compose.update('to', mentions => mentions!.delete(action.account))); + case COMPOSE_SET_GROUP_TIMELINE_VISIBLE: + return updateCompose(state, action.id, compose => compose.set('group_timeline_visible', action.groupTimelineVisible)); case ME_FETCH_SUCCESS: return updateCompose(state, 'default', compose => importAccount(compose, action.me)); case ME_PATCH_SUCCESS: