* Comment model * Framework, model, policy, presenter, api endpoint etc * Iteration, first pass of UI * fixes, refactors * Comment commands * comment socket support * typing indicators * comment component, styling * wip * right sidebar resize * fix: CMD+Enter submit * Add usePersistedState fix: Main page scrolling on comment highlight * drafts * Typing indicator * refactor * policies * Click thread to highlight Improve comment timestamps * padding * Comment menu v1 * Change comments to use editor * Basic comment editing * fix: Hide commenting button when disabled at team level * Enable opening sidebar without mark * Move selected comment to location state * Add comment delete confirmation * Add comment count to document meta * fix: Comment sidebar togglable Add copy link to comment * stash * Restore History changes * Refactor right sidebar to allow for comment animation * Update to new router best practices * stash * Various improvements * stash * Handle click outside * Fix incorrect placeholder in input fix: Input box appearing on other sessions erroneously * stash * fix: Don't leave orphaned child comments * styling * stash * Enable comment toggling again * Edit styling, merge conflicts * fix: Cannot navigate from insights to comments * Remove draft comment mark on click outside * Fix: Empty comment sidebar, tsc * Remove public toggle * fix: All comments are recessed fix: Comments should not be printed * fix: Associated mark should be removed on comment delete * Revert unused changes * Empty state, basic RTL support * Create dont toggle comment mark * Make it feel more snappy * Highlight active comment in text * fix animation * RTL support * Add reply CTA * Translations
273 lines
5.9 KiB
TypeScript
273 lines
5.9 KiB
TypeScript
import { action, autorun, computed, observable } from "mobx";
|
|
import { light as defaultTheme } from "@shared/styles/theme";
|
|
import Storage from "@shared/utils/Storage";
|
|
import Document from "~/models/Document";
|
|
import type { ConnectionStatus } from "~/scenes/Document/components/MultiplayerEditor";
|
|
|
|
const UI_STORE = "UI_STORE";
|
|
|
|
// Whether the window launched with sidebar force hidden
|
|
let sidebarHidden = window.location.search.includes("sidebarHidden=true");
|
|
|
|
export enum Theme {
|
|
Light = "light",
|
|
Dark = "dark",
|
|
System = "system",
|
|
}
|
|
|
|
export enum SystemTheme {
|
|
Light = "light",
|
|
Dark = "dark",
|
|
}
|
|
|
|
class UiStore {
|
|
// has the user seen the prompt to change the UI language and actioned it
|
|
@observable
|
|
languagePromptDismissed: boolean | undefined;
|
|
|
|
// theme represents the users UI preference (defaults to system)
|
|
@observable
|
|
theme: Theme;
|
|
|
|
// systemTheme represents the system UI theme (Settings -> General in macOS)
|
|
@observable
|
|
systemTheme: SystemTheme;
|
|
|
|
@observable
|
|
activeDocumentId: string | undefined;
|
|
|
|
@observable
|
|
activeCollectionId: string | undefined;
|
|
|
|
@observable
|
|
observingUserId: string | undefined;
|
|
|
|
@observable
|
|
commandBarOpenedFromSidebar = false;
|
|
|
|
@observable
|
|
progressBarVisible = false;
|
|
|
|
@observable
|
|
tocVisible = false;
|
|
|
|
@observable
|
|
mobileSidebarVisible = false;
|
|
|
|
@observable
|
|
sidebarWidth: number;
|
|
|
|
@observable
|
|
sidebarRightWidth: number;
|
|
|
|
@observable
|
|
sidebarCollapsed = false;
|
|
|
|
@observable
|
|
commentsCollapsed = false;
|
|
|
|
@observable
|
|
sidebarIsResizing = false;
|
|
|
|
@observable
|
|
multiplayerStatus: ConnectionStatus;
|
|
|
|
constructor() {
|
|
// Rehydrate
|
|
const data: Partial<UiStore> = Storage.get(UI_STORE) || {};
|
|
|
|
// system theme listeners
|
|
if (window.matchMedia) {
|
|
const colorSchemeQueryList = window.matchMedia(
|
|
"(prefers-color-scheme: dark)"
|
|
);
|
|
|
|
const setSystemTheme = (event: MediaQueryListEvent | MediaQueryList) => {
|
|
this.systemTheme = event.matches ? SystemTheme.Dark : SystemTheme.Light;
|
|
};
|
|
|
|
setSystemTheme(colorSchemeQueryList);
|
|
|
|
if (colorSchemeQueryList.addListener) {
|
|
colorSchemeQueryList.addListener(setSystemTheme);
|
|
}
|
|
}
|
|
|
|
// persisted keys
|
|
this.languagePromptDismissed = data.languagePromptDismissed;
|
|
this.sidebarCollapsed = !!data.sidebarCollapsed;
|
|
this.sidebarWidth = data.sidebarWidth || defaultTheme.sidebarWidth;
|
|
this.sidebarRightWidth =
|
|
data.sidebarRightWidth || defaultTheme.sidebarWidth;
|
|
this.tocVisible = !!data.tocVisible;
|
|
this.theme = data.theme || Theme.System;
|
|
|
|
autorun(() => {
|
|
Storage.set(UI_STORE, this.asJson);
|
|
});
|
|
}
|
|
|
|
@action
|
|
setTheme = (theme: Theme) => {
|
|
this.theme = theme;
|
|
Storage.set("theme", this.theme);
|
|
};
|
|
|
|
@action
|
|
setLanguagePromptDismissed = () => {
|
|
this.languagePromptDismissed = true;
|
|
};
|
|
|
|
@action
|
|
setActiveDocument = (document: Document | string): void => {
|
|
if (typeof document === "string") {
|
|
this.activeDocumentId = document;
|
|
this.observingUserId = undefined;
|
|
return;
|
|
}
|
|
|
|
this.activeDocumentId = document.id;
|
|
this.observingUserId = undefined;
|
|
|
|
if (document.isActive) {
|
|
this.activeCollectionId = document.collectionId;
|
|
}
|
|
};
|
|
|
|
@action
|
|
setMultiplayerStatus = (status: ConnectionStatus): void => {
|
|
this.multiplayerStatus = status;
|
|
};
|
|
|
|
@action
|
|
setSidebarResizing = (sidebarIsResizing: boolean): void => {
|
|
this.sidebarIsResizing = sidebarIsResizing;
|
|
};
|
|
|
|
@action
|
|
setActiveCollection = (collectionId: string | undefined): void => {
|
|
this.activeCollectionId = collectionId;
|
|
};
|
|
|
|
@action
|
|
setObservingUser = (userId: string | undefined): void => {
|
|
this.observingUserId = userId;
|
|
};
|
|
|
|
@action
|
|
clearActiveDocument = (): void => {
|
|
this.activeDocumentId = undefined;
|
|
this.observingUserId = undefined;
|
|
};
|
|
|
|
@action
|
|
setSidebarWidth = (width: number): void => {
|
|
this.sidebarWidth = width;
|
|
};
|
|
|
|
@action
|
|
collapseSidebar = () => {
|
|
this.sidebarCollapsed = true;
|
|
};
|
|
|
|
@action
|
|
expandSidebar = () => {
|
|
sidebarHidden = false;
|
|
this.sidebarCollapsed = false;
|
|
};
|
|
|
|
@action
|
|
collapseComments = () => {
|
|
this.commentsCollapsed = true;
|
|
};
|
|
|
|
@action
|
|
expandComments = () => {
|
|
this.commentsCollapsed = false;
|
|
};
|
|
|
|
@action
|
|
toggleComments = () => {
|
|
this.commentsCollapsed = !this.commentsCollapsed;
|
|
};
|
|
|
|
@action
|
|
toggleCollapsedSidebar = () => {
|
|
sidebarHidden = false;
|
|
this.sidebarCollapsed = !this.sidebarCollapsed;
|
|
};
|
|
|
|
@action
|
|
showTableOfContents = () => {
|
|
this.tocVisible = true;
|
|
};
|
|
|
|
@action
|
|
hideTableOfContents = () => {
|
|
this.tocVisible = false;
|
|
};
|
|
|
|
@action
|
|
enableProgressBar = () => {
|
|
this.progressBarVisible = true;
|
|
};
|
|
|
|
@action
|
|
disableProgressBar = () => {
|
|
this.progressBarVisible = false;
|
|
};
|
|
|
|
@action
|
|
toggleMobileSidebar = () => {
|
|
this.mobileSidebarVisible = !this.mobileSidebarVisible;
|
|
};
|
|
|
|
@action
|
|
commandBarOpened = () => {
|
|
this.commandBarOpenedFromSidebar = true;
|
|
};
|
|
|
|
@action
|
|
commandBarClosed = () => {
|
|
this.commandBarOpenedFromSidebar = false;
|
|
};
|
|
|
|
@action
|
|
hideMobileSidebar = () => {
|
|
this.mobileSidebarVisible = false;
|
|
};
|
|
|
|
/**
|
|
* Returns the current state of the sidebar taking into account user preference
|
|
* and whether the sidebar has been hidden as part of launching in a new
|
|
* desktop window.
|
|
*/
|
|
@computed
|
|
get sidebarIsClosed() {
|
|
return this.sidebarCollapsed || sidebarHidden;
|
|
}
|
|
|
|
@computed
|
|
get resolvedTheme(): Theme | SystemTheme {
|
|
if (this.theme === "system") {
|
|
return this.systemTheme;
|
|
}
|
|
|
|
return this.theme;
|
|
}
|
|
|
|
@computed
|
|
get asJson() {
|
|
return {
|
|
tocVisible: this.tocVisible,
|
|
sidebarCollapsed: this.sidebarCollapsed,
|
|
sidebarWidth: this.sidebarWidth,
|
|
sidebarRightWidth: this.sidebarRightWidth,
|
|
languagePromptDismissed: this.languagePromptDismissed,
|
|
theme: this.theme,
|
|
};
|
|
}
|
|
}
|
|
|
|
export default UiStore;
|