Skip to content

Commit

Permalink
[WiP] Add federation toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Feb 23, 2024
1 parent 6160807 commit 22448ef
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { countableText } from '../util/counter';
import { CharacterCounter } from './character_counter';
import { ContentTypeButton } from './content_type_button';
import { EditIndicator } from './edit_indicator';
import { FederationButton } from './federation_button';
import { NavigationBar } from './navigation_bar';
import { PollForm } from "./poll_form";
import { ReplyIndicator } from './reply_indicator';
Expand Down Expand Up @@ -302,6 +303,7 @@ class ComposeForm extends ImmutablePureComponent {
{!this.props.spoilerAlwaysOn && <SpoilerButtonContainer />}
<ContentTypeButton />
<EmojiPickerDropdown onPickEmoji={this.handleEmojiPick} />
<FederationButton />
<CharacterCounter max={maxChars} text={this.getFulltextForCharacterCounting()} />
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useCallback } from 'react';

import { useIntl, defineMessages } from 'react-intl';

import ShareOffIcon from '@/material-icons/400-24px/share_off.svg?react';
import { changeComposeAdvancedOption } from 'flavours/glitch/actions/compose';
import { IconButton } from 'flavours/glitch/components/icon_button';
import { useAppSelector, useAppDispatch } from 'flavours/glitch/store';

const messages = defineMessages({
enable_local_only: { id: 'compose.federation.enable_local_only', defaultMessage: 'Disallow federation for this post' },
disable_local_only: { id: 'compose.federation.disable_local_only', defaultMessage: 'Allow federation for this post' },
});

export const FederationButton = () => {
const intl = useIntl();

const disabled = useAppSelector((state) => state.getIn(['compose', 'id']) !== null);
const active = useAppSelector((state) => state.getIn(['compose', 'advanced_options', 'do_not_federate']));

const dispatch = useAppDispatch();

const handleClick = useCallback(() => {
dispatch(changeComposeAdvancedOption('do_not_federate', !active));
}, [active, dispatch]);

return (
<IconButton
onClick={handleClick}
icon={'share-off'}
iconComponent={ShareOffIcon}
title={intl.formatMessage(active ? messages.disable_local_only : messages.enable_local_only)}
active={active}
size={18}
disabled={disabled}
inverted
/>
);
};
2 changes: 2 additions & 0 deletions app/javascript/flavours/glitch/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"compose.advanced_formatting.disable_html": "Disable HTML advanced formatting",
"compose.advanced_formatting.disable_markdown": "Disable Markdown advanced formatting",
"compose.advanced_formatting.enable_markdown": "Enable Markdown advanced formatting",
"compose.federation.disable_local_only": "Allow federation for this post",
"compose.federation.enable_local_only": "Disallow federation for this post",
"compose_form.sensitive.hide": "{count, plural, one {Mark media as sensitive} other {Mark media as sensitive}}",
"compose_form.sensitive.marked": "{count, plural, one {Media is marked as sensitive} other {Media is marked as sensitive}}",
"compose_form.sensitive.unmarked": "{count, plural, one {Media is not marked as sensitive} other {Media is not marked as sensitive}}",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/material-icons/400-24px/share_off-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/javascript/material-icons/400-24px/share_off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 22448ef

Please sign in to comment.