import { observable, runInAction, action, computed } from "mobx"; import * as React from "react"; import MainViewModal from "../views/MainViewModal"; import { observer } from "mobx-react"; import { library } from '@fortawesome/fontawesome-svg-core'; import * as fa from '@fortawesome/free-solid-svg-icons'; import { SelectionManager } from "./SelectionManager"; import "./SettingsManager.scss"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Networking } from "../Network"; import { CurrentUserUtils } from "./CurrentUserUtils"; import { Utils, addStyleSheet, addStyleSheetRule, removeStyleSheetRule } from "../../Utils"; import { Doc } from "../../fields/Doc"; import GroupManager from "./GroupManager"; import GoogleAuthenticationManager from "../apis/GoogleAuthenticationManager"; import { DocServer } from "../DocServer"; import { BoolCast, StrCast, NumCast } from "../../fields/Types"; import { undoBatch } from "./UndoManager"; import { ColorState, SketchPicker } from "react-color"; const higflyout = require("@hig/flyout"); export const { anchorPoints } = higflyout; export const Flyout = higflyout.default; library.add(fa.faTimes); @observer export default class SettingsManager extends React.Component<{}> { public static Instance: SettingsManager; static _settingsStyle = addStyleSheet(); @observable private isOpen = false; @observable private dialogueBoxOpacity = 1; @observable private overlayOpacity = 0.4; @observable private settingsContent = "password"; @observable private errorText = ""; @observable private successText = ""; @observable private playgroundMode = false; private curr_password_ref = React.createRef(); private new_password_ref = React.createRef(); private new_confirm_ref = React.createRef(); @computed get backgroundColor() { return Doc.UserDoc().defaultColor; } public open = action(() => { SelectionManager.DeselectAll(); this.isOpen = true; }); public close = action(() => { this.isOpen = false; }); constructor(props: {}) { super(props); SettingsManager.Instance = this; } @action private dispatchRequest = async () => { const curr_pass = this.curr_password_ref.current?.value; const new_pass = this.new_password_ref.current?.value; const new_confirm = this.new_confirm_ref.current?.value; if (!(curr_pass && new_pass && new_confirm)) { this.changeAlertText("Hey, we're missing some fields!", ""); return; } const passwordBundle = { curr_pass, new_pass, new_confirm }; const { error } = await Networking.PostToServer('/internalResetPassword', passwordBundle); if (error) { this.changeAlertText("Uh oh! " + error[0].msg + "...", ""); return; } this.changeAlertText("", "Password successfully updated!"); } @action private changeAlertText = (errortxt: string, successtxt: string) => { this.errorText = errortxt; this.successText = successtxt; } @action onClick = (event: any) => { this.settingsContent = event.currentTarget.value; this.errorText = ""; this.successText = ""; } @action noviceToggle = (event: any) => { Doc.UserDoc().noviceMode = !Doc.UserDoc().noviceMode; } @action googleAuthorize = (event: any) => { GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken(true); } @action togglePlaygroundMode = () => { this.playgroundMode = !this.playgroundMode; if (this.playgroundMode) DocServer.Control.makeReadOnly(); else DocServer.Control.makeEditable(); addStyleSheetRule(SettingsManager._settingsStyle, "lm_header", { background: "pink !important" }); } @action changeMode = (e: any) => { if (e.currentTarget.value === "Novice") { Doc.UserDoc().noviceMode = true; } else { Doc.UserDoc().noviceMode = false; } } @action changeFontFamily = (e: any) => { Doc.UserDoc().fontFamily = e.currentTarget.value; } @action changeFontSize = (e: any) => { Doc.UserDoc().fontSize = e.currentTarget.value; } @action @undoBatch switchColor = (color: ColorState) => { const val = String(color.hex); Doc.UserDoc().defaultColor = val; return true; } private get settingsInterface() { const passwordContent =
{this.errorText ?
{this.errorText}
: undefined} {this.successText ?
{this.successText}
: undefined} forgot password?
; const modesContent =
this.togglePlaygroundMode()))} />
Playground Mode
; const accountsContent =
; const colorBox = ; const colorFlyout =
e.stopPropagation()} >
; const fontFamilies: string[] = ["Times New Roman", "Arial", "Georgia", "Comic Sans MS", "Tahoma", "Impact", "Crimson Text"]; const fontSizes: string[] = ["7pt", "8pt", "9pt", "10pt", "12pt", "14pt", "16pt", "18pt", "20pt", "24pt", "32pt", "48pt", "72pt"]; const preferencesContent =
Background Color
{colorFlyout}
Default Font
; return (
Settings
{Doc.CurrentUserEmail}
Password
{passwordContent}
Modes
{modesContent}
Accounts
{accountsContent}
Preferences
{preferencesContent}
); } render() { return ( ); } }