[HD-19 #resolve] Merge pull request #126

This commit is contained in:
Marquis Kurt 2019-11-19 15:52:42 -05:00 committed by GitHub
commit aedb332f68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 20 deletions

View File

@ -39,7 +39,11 @@ import ComposeMediaAttachment from "../components/ComposeMediaAttachment";
import EmojiPicker from "../components/EmojiPicker"; import EmojiPicker from "../components/EmojiPicker";
import { DateTimePicker, MuiPickersUtilsProvider } from "material-ui-pickers"; import { DateTimePicker, MuiPickersUtilsProvider } from "material-ui-pickers";
import MomentUtils from "@date-io/moment"; import MomentUtils from "@date-io/moment";
import { getUserDefaultVisibility, getConfig } from "../utilities/settings"; import {
getUserDefaultVisibility,
getConfig,
getUserDefaultBool
} from "../utilities/settings";
interface IComposerState { interface IComposerState {
account: UAccount; account: UAccount;
@ -75,7 +79,9 @@ class Composer extends Component<any, IComposerState> {
sensitive: false, sensitive: false,
visibilityMenu: false, visibilityMenu: false,
text: "", text: "",
remainingChars: 500, remainingChars: getUserDefaultBool("imposeCharacterLimit")
? 500
: 9999999999999,
showEmojis: false, showEmojis: false,
federated: true federated: true
}; };
@ -95,7 +101,9 @@ class Composer extends Component<any, IComposerState> {
acct: state.acct, acct: state.acct,
visibility: state.visibility, visibility: state.visibility,
text, text,
remainingChars: 500 - text.length remainingChars: getUserDefaultBool("imposeCharacterLimit")
? 500 - text.length
: 99999999
}); });
}); });
} }
@ -108,7 +116,9 @@ class Composer extends Component<any, IComposerState> {
acct: state.acct, acct: state.acct,
visibility: state.visibility, visibility: state.visibility,
text, text,
remainingChars: 500 - text.length remainingChars: getUserDefaultBool("imposeCharacterLimit")
? 500 - text.length
: 99999999
}); });
} }
@ -145,7 +155,12 @@ class Composer extends Component<any, IComposerState> {
} }
updateTextFromField(text: string) { updateTextFromField(text: string) {
this.setState({ text, remainingChars: 500 - text.length }); this.setState({
text,
remainingChars: getUserDefaultBool("imposeCharacterLimit")
? 500 - text.length
: 99999999
});
} }
updateWarningFromField(sensitiveText: string) { updateWarningFromField(sensitiveText: string) {
@ -467,18 +482,28 @@ class Composer extends Component<any, IComposerState> {
}} }}
value={this.state.text} value={this.state.text}
/> />
<Typography {getUserDefaultBool("imposeCharacterLimit") ? (
variant="caption" <Typography
className={ variant="caption"
this.state.remainingChars <= 100 className={
? classes.charsReachingLimit this.state.remainingChars <= 100
: null ? classes.charsReachingLimit
} : null
> }
{`${this.state.remainingChars} character${ >
this.state.remainingChars === 1 ? "" : "s" {`${this.state.remainingChars} character${
} remaining`} this.state.remainingChars === 1 ? "" : "s"
</Typography> } remaining`}
</Typography>
) : (
<Typography variant="caption">
<WarningIcon className={classes.warningCaption} />{" "}
You have the character limit turned off. Make sure
that your post matches your instance's character
limit before posting.
</Typography>
)}
{this.state.attachments && {this.state.attachments &&
this.state.attachments.length > 0 ? ( this.state.attachments.length > 0 ? (
<div className={classes.composeAttachmentArea}> <div className={classes.composeAttachmentArea}>

View File

@ -63,6 +63,7 @@ import RefreshIcon from "@material-ui/icons/Refresh";
import UndoIcon from "@material-ui/icons/Undo"; import UndoIcon from "@material-ui/icons/Undo";
import DomainDisabledIcon from "@material-ui/icons/DomainDisabled"; import DomainDisabledIcon from "@material-ui/icons/DomainDisabled";
import AccountSettingsIcon from "mdi-material-ui/AccountSettings"; import AccountSettingsIcon from "mdi-material-ui/AccountSettings";
import AlphabeticalVariantOffIcon from "mdi-material-ui/AlphabeticalVariantOff";
import { Config } from "../types/Config"; import { Config } from "../types/Config";
import { Account } from "../types/Account"; import { Account } from "../types/Account";
@ -84,6 +85,7 @@ interface ISettingsState {
brandName: string; brandName: string;
federated: boolean; federated: boolean;
currentUser?: Account; currentUser?: Account;
imposeCharacterLimit: boolean;
} }
class SettingsPage extends Component<any, ISettingsState> { class SettingsPage extends Component<any, ISettingsState> {
@ -114,7 +116,8 @@ class SettingsPage extends Component<any, ISettingsState> {
setHyperspaceTheme(defaultTheme), setHyperspaceTheme(defaultTheme),
defaultVisibility: getUserDefaultVisibility() || "public", defaultVisibility: getUserDefaultVisibility() || "public",
brandName: "Hyperspace", brandName: "Hyperspace",
federated: true federated: true,
imposeCharacterLimit: getUserDefaultBool("imposeCharacterLimit")
}; };
this.toggleDarkMode = this.toggleDarkMode.bind(this); this.toggleDarkMode = this.toggleDarkMode.bind(this);
@ -218,6 +221,16 @@ class SettingsPage extends Component<any, ISettingsState> {
}); });
} }
toggleCharacterLimit() {
this.setState({
imposeCharacterLimit: !this.state.imposeCharacterLimit
});
setUserDefaultBool(
"imposeCharacterLimit",
!this.state.imposeCharacterLimit
);
}
toggleResetDialog() { toggleResetDialog() {
this.setState({ this.setState({
resetHyperspaceDialog: !this.state.resetHyperspaceDialog resetHyperspaceDialog: !this.state.resetHyperspaceDialog
@ -632,6 +645,25 @@ class SettingsPage extends Component<any, ISettingsState> {
</Button> </Button>
</ListItemSecondaryAction> </ListItemSecondaryAction>
</ListItem> </ListItem>
<ListItem>
<ListItemAvatar>
<AlphabeticalVariantOffIcon color="action" />
</ListItemAvatar>
<ListItemText
primary="Impose character limit"
secondary="Impose a character limit when creating posts"
/>
<ListItemSecondaryAction>
<Switch
checked={
this.state.imposeCharacterLimit
}
onChange={() =>
this.toggleCharacterLimit()
}
/>
</ListItemSecondaryAction>
</ListItem>
</List> </List>
</Paper> </Paper>
<br /> <br />

View File

@ -12,6 +12,7 @@ type SettingsTemplate = {
clearNotificationsOnRead: boolean; clearNotificationsOnRead: boolean;
displayAllOnNotificationBadge: boolean; displayAllOnNotificationBadge: boolean;
defaultVisibility: string; defaultVisibility: string;
imposeCharacterLimit: boolean;
}; };
/** /**
@ -99,7 +100,8 @@ export function createUserDefaults() {
enablePushNotifications: true, enablePushNotifications: true,
clearNotificationsOnRead: false, clearNotificationsOnRead: false,
displayAllOnNotificationBadge: false, displayAllOnNotificationBadge: false,
defaultVisibility: "public" defaultVisibility: "public",
imposeCharacterLimit: true
}; };
let settings = [ let settings = [
@ -107,7 +109,8 @@ export function createUserDefaults() {
"systemDecidesDarkMode", "systemDecidesDarkMode",
"clearNotificationsOnRead", "clearNotificationsOnRead",
"displayAllOnNotificationBadge", "displayAllOnNotificationBadge",
"defaultVisibility" "defaultVisibility",
"imposeCharacterLimit"
]; ];
migrateExistingSettings(); migrateExistingSettings();