[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 { DateTimePicker, MuiPickersUtilsProvider } from "material-ui-pickers";
import MomentUtils from "@date-io/moment";
import { getUserDefaultVisibility, getConfig } from "../utilities/settings";
import {
getUserDefaultVisibility,
getConfig,
getUserDefaultBool
} from "../utilities/settings";
interface IComposerState {
account: UAccount;
@ -75,7 +79,9 @@ class Composer extends Component<any, IComposerState> {
sensitive: false,
visibilityMenu: false,
text: "",
remainingChars: 500,
remainingChars: getUserDefaultBool("imposeCharacterLimit")
? 500
: 9999999999999,
showEmojis: false,
federated: true
};
@ -95,7 +101,9 @@ class Composer extends Component<any, IComposerState> {
acct: state.acct,
visibility: state.visibility,
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,
visibility: state.visibility,
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) {
this.setState({ text, remainingChars: 500 - text.length });
this.setState({
text,
remainingChars: getUserDefaultBool("imposeCharacterLimit")
? 500 - text.length
: 99999999
});
}
updateWarningFromField(sensitiveText: string) {
@ -467,18 +482,28 @@ class Composer extends Component<any, IComposerState> {
}}
value={this.state.text}
/>
<Typography
variant="caption"
className={
this.state.remainingChars <= 100
? classes.charsReachingLimit
: null
}
>
{`${this.state.remainingChars} character${
this.state.remainingChars === 1 ? "" : "s"
} remaining`}
</Typography>
{getUserDefaultBool("imposeCharacterLimit") ? (
<Typography
variant="caption"
className={
this.state.remainingChars <= 100
? classes.charsReachingLimit
: null
}
>
{`${this.state.remainingChars} character${
this.state.remainingChars === 1 ? "" : "s"
} 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.length > 0 ? (
<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 DomainDisabledIcon from "@material-ui/icons/DomainDisabled";
import AccountSettingsIcon from "mdi-material-ui/AccountSettings";
import AlphabeticalVariantOffIcon from "mdi-material-ui/AlphabeticalVariantOff";
import { Config } from "../types/Config";
import { Account } from "../types/Account";
@ -84,6 +85,7 @@ interface ISettingsState {
brandName: string;
federated: boolean;
currentUser?: Account;
imposeCharacterLimit: boolean;
}
class SettingsPage extends Component<any, ISettingsState> {
@ -114,7 +116,8 @@ class SettingsPage extends Component<any, ISettingsState> {
setHyperspaceTheme(defaultTheme),
defaultVisibility: getUserDefaultVisibility() || "public",
brandName: "Hyperspace",
federated: true
federated: true,
imposeCharacterLimit: getUserDefaultBool("imposeCharacterLimit")
};
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() {
this.setState({
resetHyperspaceDialog: !this.state.resetHyperspaceDialog
@ -632,6 +645,25 @@ class SettingsPage extends Component<any, ISettingsState> {
</Button>
</ListItemSecondaryAction>
</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>
</Paper>
<br />

View File

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