chore: Enable eslint to enforce curly (#3060)

This commit is contained in:
Tom Moor
2022-02-05 10:15:40 -08:00
committed by GitHub
parent c7df74fcc4
commit c5a11fe17b
103 changed files with 1175 additions and 397 deletions

View File

@@ -52,7 +52,9 @@ export const editCollection = createAction({
!!activeCollectionId &&
stores.policies.abilities(activeCollectionId).update,
perform: ({ t, activeCollectionId }) => {
if (!activeCollectionId) return;
if (!activeCollectionId) {
return;
}
stores.dialogs.openModal({
title: t("Edit collection"),

View File

@@ -61,14 +61,18 @@ export const starDocument = createAction({
icon: <StarredIcon />,
keywords: "favorite bookmark",
visible: ({ activeDocumentId, stores }) => {
if (!activeDocumentId) return false;
if (!activeDocumentId) {
return false;
}
const document = stores.documents.get(activeDocumentId);
return (
!document?.isStarred && stores.policies.abilities(activeDocumentId).star
);
},
perform: ({ activeDocumentId, stores }) => {
if (!activeDocumentId) return;
if (!activeDocumentId) {
return;
}
const document = stores.documents.get(activeDocumentId);
document?.star();
@@ -81,7 +85,9 @@ export const unstarDocument = createAction({
icon: <UnstarredIcon />,
keywords: "unfavorite unbookmark",
visible: ({ activeDocumentId, stores }) => {
if (!activeDocumentId) return false;
if (!activeDocumentId) {
return false;
}
const document = stores.documents.get(activeDocumentId);
return (
!!document?.isStarred &&
@@ -89,7 +95,9 @@ export const unstarDocument = createAction({
);
},
perform: ({ activeDocumentId, stores }) => {
if (!activeDocumentId) return;
if (!activeDocumentId) {
return;
}
const document = stores.documents.get(activeDocumentId);
document?.unstar();
@@ -105,7 +113,9 @@ export const downloadDocument = createAction({
visible: ({ activeDocumentId, stores }) =>
!!activeDocumentId && stores.policies.abilities(activeDocumentId).download,
perform: ({ activeDocumentId, stores }) => {
if (!activeDocumentId) return;
if (!activeDocumentId) {
return;
}
const document = stores.documents.get(activeDocumentId);
document?.download();
@@ -121,7 +131,9 @@ export const duplicateDocument = createAction({
visible: ({ activeDocumentId, stores }) =>
!!activeDocumentId && stores.policies.abilities(activeDocumentId).update,
perform: async ({ activeDocumentId, t, stores }) => {
if (!activeDocumentId) return;
if (!activeDocumentId) {
return;
}
const document = stores.documents.get(activeDocumentId);
invariant(document, "Document must exist");
@@ -189,7 +201,9 @@ export const pinDocumentToHome = createAction({
);
},
perform: async ({ activeDocumentId, location, t, stores }) => {
if (!activeDocumentId) return;
if (!activeDocumentId) {
return;
}
const document = stores.documents.get(activeDocumentId);
await document?.pin();
@@ -265,7 +279,9 @@ export const createTemplate = createAction({
icon: <ShapesIcon />,
keywords: "new create template",
visible: ({ activeCollectionId, activeDocumentId, stores }) => {
if (!activeDocumentId) return false;
if (!activeDocumentId) {
return false;
}
const document = stores.documents.get(activeDocumentId);
return (
!!activeCollectionId &&
@@ -274,7 +290,9 @@ export const createTemplate = createAction({
);
},
perform: ({ activeDocumentId, stores, t, event }) => {
if (!activeDocumentId) return;
if (!activeDocumentId) {
return;
}
event?.preventDefault();
event?.stopPropagation();

View File

@@ -55,9 +55,13 @@ class AuthenticatedLayout extends React.Component<Props> {
goToNewDocument = () => {
const { activeCollectionId } = this.props.ui;
if (!activeCollectionId) return;
if (!activeCollectionId) {
return;
}
const can = this.props.policies.abilities(activeCollectionId);
if (!can.update) return;
if (!can.update) {
return;
}
history.push(newDocumentPath(activeCollectionId));
};
@@ -65,7 +69,9 @@ class AuthenticatedLayout extends React.Component<Props> {
const { auth } = this.props;
const { user, team } = auth;
const showSidebar = auth.authenticated && user && team;
if (auth.isSuspended) return <ErrorSuspended />;
if (auth.isSuspended) {
return <ErrorSuspended />;
}
const sidebar = showSidebar ? (
<Switch>

View File

@@ -72,13 +72,18 @@ export function filterTemplateItems(items: TMenuItem[]): TMenuItem[] {
// this block literally just trims unnecessary separators
filtered = filtered.reduce((acc, item, index) => {
// trim separators from start / end
if (item.type === "separator" && index === 0) return acc;
if (item.type === "separator" && index === filtered.length - 1) return acc;
if (item.type === "separator" && index === 0) {
return acc;
}
if (item.type === "separator" && index === filtered.length - 1) {
return acc;
}
// trim double separators looking ahead / behind
const prev = filtered[index - 1];
if (prev && prev.type === "separator" && item.type === "separator")
if (prev && prev.type === "separator" && item.type === "separator") {
return acc;
}
// otherwise, continue
return [...acc, item];

View File

@@ -28,7 +28,9 @@ function HoverPreviewInternal({ node, onClose }: Props) {
const startCloseTimer = () => {
stopOpenTimer();
timerClose.current = setTimeout(() => {
if (isVisible) setVisible(false);
if (isVisible) {
setVisible(false);
}
onClose();
}, DELAY_CLOSE);
};

View File

@@ -21,7 +21,9 @@ function HoverPreviewDocument({ url, children }: Props) {
}
const document = slug ? documents.getByUrl(slug) : undefined;
if (!document) return null;
if (!document) {
return null;
}
return (
<>

View File

@@ -84,7 +84,9 @@ const InputSelect = (props: Props) => {
);
React.useEffect(() => {
if (previousValue.current === select.selectedValue) return;
if (previousValue.current === select.selectedValue) {
return;
}
previousValue.current = select.selectedValue;
async function load() {

View File

@@ -70,7 +70,9 @@ class PaginatedList extends React.Component<Props> {
};
fetchResults = async () => {
if (!this.props.fetch) return;
if (!this.props.fetch) {
return;
}
this.isFetching = true;
const limit = DEFAULT_PAGINATION_LIMIT;
const results = await this.props.fetch({
@@ -94,7 +96,9 @@ class PaginatedList extends React.Component<Props> {
@action
loadMoreResults = async () => {
// Don't paginate if there aren't more results or were currently fetching
if (!this.allowLoadMore || this.isFetching) return;
if (!this.allowLoadMore || this.isFetching) {
return;
}
// If there are already cached results that we haven't yet rendered because
// of lazy rendering then show another page.
const leftToRender = this.props.items.length - this.renderCount;

View File

@@ -22,7 +22,9 @@ class PathToDocument extends React.Component<Props> {
handleClick = async (ev: React.SyntheticEvent) => {
ev.preventDefault();
const { document, result, onSuccess } = this.props;
if (!document) return;
if (!document) {
return;
}
if (result.type === "document") {
await document.move(result.collectionId, result.id);
@@ -30,13 +32,17 @@ class PathToDocument extends React.Component<Props> {
await document.move(result.collectionId);
}
if (onSuccess) onSuccess();
if (onSuccess) {
onSuccess();
}
};
render() {
const { result, collection, document, ref, style } = this.props;
const Component = document ? ResultWrapperLink : ResultWrapper;
if (!result) return <div />;
if (!result) {
return <div />;
}
return (
// @ts-expect-error ts-migrate(2604) FIXME: JSX element type 'Component' does not have any con... Remove this comment to see the full error message

View File

@@ -12,13 +12,16 @@ export default function ScrollToTop({ children }: Props) {
const previousLocationPathname = usePrevious(location.pathname);
React.useEffect(() => {
if (location.pathname === previousLocationPathname) return;
if (location.pathname === previousLocationPathname) {
return;
}
// exception for when entering or exiting document edit, scroll position should not reset
if (
location.pathname.match(/\/edit\/?$/) ||
previousLocationPathname?.match(/\/edit\/?$/)
)
) {
return;
}
window.scrollTo(0, 0);
}, [location.pathname, previousLocationPathname]);

View File

@@ -21,7 +21,9 @@ function Scrollable(
const { height } = useWindowSize();
const updateShadows = React.useCallback(() => {
const c = (ref || fallbackRef).current;
if (!c) return;
if (!c) {
return;
}
const scrollTop = c.scrollTop;
const tsv = !!((shadow || topShadow) && scrollTop > 0);

View File

@@ -79,8 +79,12 @@ function CollectionLink({
accept: "document",
drop: (item: DragObject, monitor) => {
const { id, collectionId } = item;
if (monitor.didDrop()) return;
if (!collection) return;
if (monitor.didDrop()) {
return;
}
if (!collection) {
return;
}
const document = documents.get(id);
if (collection.id === collectionId && !document?.parentDocumentId) {
@@ -115,7 +119,9 @@ function CollectionLink({
const [{ isOverReorder }, dropToReorder] = useDrop({
accept: "document",
drop: async (item: DragObject) => {
if (!collection) return;
if (!collection) {
return;
}
documents.move(item.id, collection.id, undefined, 0);
},
collect: (monitor) => ({

View File

@@ -112,7 +112,9 @@ function DocumentLink(
const handleTitleChange = React.useCallback(
async (title: string) => {
if (!document) return;
if (!document) {
return;
}
await documents.update(
{
id: document.id,
@@ -167,8 +169,12 @@ function DocumentLink(
const [{ isOverReparent, canDropToReparent }, dropToReparent] = useDrop({
accept: "document",
drop: (item: DragObject, monitor) => {
if (monitor.didDrop()) return;
if (!collection) return;
if (monitor.didDrop()) {
return;
}
if (!collection) {
return;
}
documents.move(item.id, collection.id, node.id);
},
canDrop: (_item, monitor) =>
@@ -212,8 +218,12 @@ function DocumentLink(
const [{ isOverReorder, isDraggingAnyDocument }, dropToReorder] = useDrop({
accept: "document",
drop: (item: DragObject) => {
if (!collection) return;
if (item.id === node.id) return;
if (!collection) {
return;
}
if (item.id === node.id) {
return;
}
if (expanded) {
documents.move(item.id, collection.id, node.id, 0);

View File

@@ -67,7 +67,9 @@ function StarredLink({
const handleTitleChange = React.useCallback(
async (title: string) => {
if (!document) return;
if (!document) {
return;
}
await documents.update(
{
id: document.id,

View File

@@ -79,7 +79,9 @@ class SocketProvider extends React.Component<Props> {
views,
fileOperations,
} = this.props;
if (!auth.token) return;
if (!auth.token) {
return;
}
this.socket.on("connect", () => {
// immediately send current users token to the websocket backend where it
@@ -329,8 +331,9 @@ class SocketProvider extends React.Component<Props> {
this.socket.on("fileOperations.update", async (event: any) => {
const user = auth.user;
let collection = null;
if (event.collectionId)
if (event.collectionId) {
collection = await collections.fetch(event.collectionId);
}
if (user) {
fileOperations.add({ ...event, user, collection });

View File

@@ -63,7 +63,9 @@ const Tabs = ({ children }: { children: React.ReactNode }) => {
const updateShadows = React.useCallback(() => {
const c = ref.current;
if (!c) return;
if (!c) {
return;
}
const scrollLeft = c.scrollLeft;
const wrapperWidth = c.scrollWidth - c.clientWidth;
const fade = !!(wrapperWidth - scrollLeft !== 0);

View File

@@ -106,7 +106,9 @@ class CommandMenu<T = MenuItem> extends React.Component<Props<T>, State> {
}
handleKeyDown = (event: KeyboardEvent) => {
if (!this.props.isActive) return;
if (!this.props.isActive) {
return;
}
if (event.key === "Enter") {
event.preventDefault();
@@ -196,8 +198,12 @@ class CommandMenu<T = MenuItem> extends React.Component<Props<T>, State> {
};
handleLinkInputKeydown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (!this.props.isActive) return;
if (!this.state.insertItem) return;
if (!this.props.isActive) {
return;
}
if (!this.state.insertItem) {
return;
}
if (event.key === "Enter") {
event.preventDefault();
@@ -229,8 +235,12 @@ class CommandMenu<T = MenuItem> extends React.Component<Props<T>, State> {
};
handleLinkInputPaste = (event: React.ClipboardEvent<HTMLInputElement>) => {
if (!this.props.isActive) return;
if (!this.state.insertItem) return;
if (!this.props.isActive) {
return;
}
if (!this.state.insertItem) {
return;
}
const href = event.clipboardData.getData("text/plain");
const matches = this.state.insertItem.matcher(href);
@@ -423,7 +433,9 @@ class CommandMenu<T = MenuItem> extends React.Component<Props<T>, State> {
}
const filtered = items.filter((item) => {
if (item.name === "separator") return true;
if (item.name === "separator") {
return true;
}
// Some extensions may be disabled, remove corresponding menu items
if (
@@ -435,10 +447,14 @@ class CommandMenu<T = MenuItem> extends React.Component<Props<T>, State> {
}
// If no image upload callback has been passed, filter the image block out
if (!uploadImage && item.name === "image") return false;
if (!uploadImage && item.name === "image") {
return false;
}
// some items (defaultHidden) are not visible until a search query exists
if (!search) return !item.defaultHidden;
if (!search) {
return !item.defaultHidden;
}
const n = search.toLowerCase();
if (!filterable) {

View File

@@ -105,7 +105,9 @@ class LinkEditor extends React.Component<Props, State> {
save = (href: string, title?: string): void => {
href = href.trim();
if (href.length === 0) return;
if (href.length === 0) {
return;
}
this.discardInputValue = true;
const { from, to } = this.props;
@@ -163,7 +165,9 @@ class LinkEditor extends React.Component<Props, State> {
}
case "ArrowUp": {
if (event.shiftKey) return;
if (event.shiftKey) {
return;
}
event.preventDefault();
event.stopPropagation();
const prevIndex = this.state.selectedIndex - 1;
@@ -176,7 +180,9 @@ class LinkEditor extends React.Component<Props, State> {
case "ArrowDown":
case "Tab": {
if (event.shiftKey) return;
if (event.shiftKey) {
return;
}
event.preventDefault();
event.stopPropagation();
@@ -239,9 +245,13 @@ class LinkEditor extends React.Component<Props, State> {
const { onCreateLink } = this.props;
value = value.trim();
if (value.length === 0) return;
if (value.length === 0) {
return;
}
if (onCreateLink) return onCreateLink(value);
if (onCreateLink) {
return onCreateLink(value);
}
};
handleRemoveLink = (): void => {

View File

@@ -44,8 +44,12 @@ function isVisible(props: Props) {
const { view } = props;
const { selection } = view.state;
if (!selection) return false;
if (selection.empty) return false;
if (!selection) {
return false;
}
if (selection.empty) {
return false;
}
if (selection instanceof NodeSelection && selection.node.type.name === "hr") {
return true;
}
@@ -209,8 +213,12 @@ export default class SelectionToolbar extends React.Component<Props> {
// Some extensions may be disabled, remove corresponding items
items = items.filter((item) => {
if (item.name === "separator") return true;
if (item.name && !this.props.commands[item.name]) return false;
if (item.name === "separator") {
return true;
}
if (item.name && !this.props.commands[item.name]) {
return false;
}
return true;
});

View File

@@ -233,7 +233,9 @@ export class Editor extends React.PureComponent<
this.calculateDir();
if (this.props.readOnly) return;
if (this.props.readOnly) {
return;
}
if (this.props.autoFocus) {
this.focusAtEnd();
@@ -581,11 +583,15 @@ export class Editor extends React.PureComponent<
}
scrollToAnchor(hash: string) {
if (!hash) return;
if (!hash) {
return;
}
try {
const element = document.querySelector(hash);
if (element) element.scrollIntoView({ behavior: "smooth" });
if (element) {
element.scrollIntoView({ behavior: "smooth" });
}
} catch (err) {
// querySelector will throw an error if the hash begins with a number
// or contains a period. This is protected against now by safeSlugify
@@ -595,7 +601,9 @@ export class Editor extends React.PureComponent<
}
calculateDir = () => {
if (!this.element) return;
if (!this.element) {
return;
}
const isRTL =
this.props.dir === "rtl" ||
@@ -611,7 +619,9 @@ export class Editor extends React.PureComponent<
};
handleChange = () => {
if (!this.props.onChange) return;
if (!this.props.onChange) {
return;
}
this.props.onChange(() => {
return this.value();
@@ -661,7 +671,9 @@ export class Editor extends React.PureComponent<
};
handleCloseBlockMenu = () => {
if (!this.state.blockMenuOpen) return;
if (!this.state.blockMenuOpen) {
return;
}
this.setState({ blockMenuOpen: false });
};

View File

@@ -87,7 +87,9 @@ if (element) {
window.addEventListener("load", async () => {
// installation does not use Google Analytics, or tracking is blocked on client
// no point loading the rest of the analytics bundles
if (!env.GOOGLE_ANALYTICS_ID || !window.ga) return;
if (!env.GOOGLE_ANALYTICS_ID || !window.ga) {
return;
}
// https://github.com/googleanalytics/autotrack/issues/137#issuecomment-305890099
await import(
/* webpackChunkName: "autotrack" */

View File

@@ -298,7 +298,9 @@ export default class Document extends BaseModel {
lastRevision?: number;
}
) => {
if (this.isSaving) return this;
if (this.isSaving) {
return this;
}
this.isSaving = true;
try {
@@ -325,7 +327,9 @@ export default class Document extends BaseModel {
@action
save = async (options?: SaveOptions | undefined) => {
if (this.isSaving) return this;
if (this.isSaving) {
return this;
}
const isCreating = !this.id;
this.isSaving = true;
@@ -422,7 +426,9 @@ export default class Document extends BaseModel {
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
// Firefox support requires the anchor tag be in the DOM to trigger the dl
if (document.body) document.body.appendChild(a);
if (document.body) {
document.body.appendChild(a);
}
a.href = url;
a.download = `${this.titleWithDefault}.md`;
a.click();

View File

@@ -80,7 +80,9 @@ class AddGroupsToCollection extends React.Component<Props> {
render() {
const { groups, policies, collection, auth, t } = this.props;
const { user, team } = auth;
if (!user || !team) return null;
if (!user || !team) {
return null;
}
const can = policies.abilities(team.id);

View File

@@ -77,7 +77,9 @@ class AddPeopleToCollection extends React.Component<Props> {
render() {
const { users, collection, auth, t } = this.props;
const { user, team } = auth;
if (!user || !team) return null;
if (!user || !team) {
return null;
}
return (
<Flex column>

View File

@@ -194,7 +194,9 @@ class DocumentScene extends React.Component<Props> {
};
goToMove = (ev: KeyboardEvent) => {
if (!this.props.readOnly) return;
if (!this.props.readOnly) {
return;
}
ev.preventDefault();
const { document, abilities } = this.props;
@@ -204,7 +206,9 @@ class DocumentScene extends React.Component<Props> {
};
goToEdit = (ev: KeyboardEvent) => {
if (!this.props.readOnly) return;
if (!this.props.readOnly) {
return;
}
ev.preventDefault();
const { document, abilities } = this.props;
@@ -214,8 +218,12 @@ class DocumentScene extends React.Component<Props> {
};
goToHistory = (ev: KeyboardEvent) => {
if (!this.props.readOnly) return;
if (ev.ctrlKey) return;
if (!this.props.readOnly) {
return;
}
if (ev.ctrlKey) {
return;
}
ev.preventDefault();
const { document, location } = this.props;
@@ -229,7 +237,9 @@ class DocumentScene extends React.Component<Props> {
onPublish = (ev: React.MouseEvent | KeyboardEvent) => {
ev.preventDefault();
const { document } = this.props;
if (document.publishedAt) return;
if (document.publishedAt) {
return;
}
this.onSave({
publish: true,
done: true,
@@ -237,7 +247,9 @@ class DocumentScene extends React.Component<Props> {
};
onToggleTableOfContents = (ev: KeyboardEvent) => {
if (!this.props.readOnly) return;
if (!this.props.readOnly) {
return;
}
ev.preventDefault();
const { ui } = this.props;
@@ -257,13 +269,17 @@ class DocumentScene extends React.Component<Props> {
) => {
const { document, auth } = this.props;
// prevent saves when we are already saving
if (document.isSaving) return;
if (document.isSaving) {
return;
}
// get the latest version of the editor text value
const text = this.getEditorText ? this.getEditorText() : document.text;
// prevent save before anything has been written (single hash is empty doc)
if (text.trim() === "" && document.title.trim() === "") return;
if (text.trim() === "" && document.title.trim() === "") {
return;
}
document.text = text;
document.tasks = getTasks(document.text);

View File

@@ -22,7 +22,9 @@ function PublicReferences(props: Props) {
let result: NavigationNode[];
function findChildren(node?: NavigationNode) {
if (!node) return;
if (!node) {
return;
}
if (node.id === documentId) {
result = node.children;

View File

@@ -58,7 +58,9 @@ export default class SocketPresence extends React.Component<Props> {
};
emitJoin = () => {
if (!this.context) return;
if (!this.context) {
return;
}
this.context.emit("join", {
documentId: this.props.documentId,
isEditing: this.props.isEditing,
@@ -66,7 +68,9 @@ export default class SocketPresence extends React.Component<Props> {
};
emitPresence = () => {
if (!this.context) return;
if (!this.context) {
return;
}
this.context.emit("presence", {
documentId: this.props.documentId,
isEditing: this.props.isEditing,

View File

@@ -76,7 +76,9 @@ class AddPeopleToGroup extends React.Component<Props> {
render() {
const { users, group, auth, t } = this.props;
const { user, team } = auth;
if (!user || !team) return null;
if (!user || !team) {
return null;
}
return (
<Flex column>

View File

@@ -177,14 +177,18 @@ class Search extends React.Component<Props> {
get title() {
const query = this.query;
const title = this.props.t("Search");
if (query) return `${query} ${title}`;
if (query) {
return `${query} ${title}`;
}
return title;
}
@action
loadMoreResults = async () => {
// Don't paginate if there aren't more results or were in the middle of fetching
if (!this.allowLoadMore || this.isLoading) return;
if (!this.allowLoadMore || this.isLoading) {
return;
}
// Fetch more results
await this.fetchResults();
@@ -330,7 +334,9 @@ class Search extends React.Component<Props> {
>
{results.map((result, index) => {
const document = documents.data.get(result.document.id);
if (!document) return null;
if (!document) {
return null;
}
return (
<DocumentListItem
ref={(ref) => index === 0 && this.setFirstDocumentRef(ref)}

View File

@@ -30,7 +30,9 @@ function UserProfile(props: Props) {
const currentUser = useCurrentUser();
const history = useHistory();
const { user, ...rest } = props;
if (!user) return null;
if (!user) {
return null;
}
const isCurrentUser = currentUser.id === user.id;
return (

View File

@@ -89,7 +89,9 @@ export default class AuthStore {
event.newValue
);
// data may be null if key is deleted in localStorage
if (!data) return;
if (!data) {
return;
}
// If we're not signed in then hydrate from the received data, otherwise if
// we are signed in and the received data contains no user then sign out

View File

@@ -111,7 +111,9 @@ export default class BaseStore<T extends BaseModel> {
}
save(params: Partial<T>): Promise<T> {
if (params.id) return this.update(params);
if (params.id) {
return this.update(params);
}
return this.create(params);
}
@@ -195,7 +197,9 @@ export default class BaseStore<T extends BaseModel> {
}
const item = this.data.get(id);
if (item && !options.force) return item;
if (item && !options.force) {
return item;
}
this.isFetching = true;
try {

View File

@@ -141,7 +141,9 @@ export default class CollectionsStore extends BaseStore<Collection> {
@action
async fetch(id: string, options: Record<string, any> = {}): Promise<any> {
const item = this.get(id) || this.getByUrl(id);
if (item && !options.force) return item;
if (item && !options.force) {
return item;
}
this.isFetching = true;
try {

View File

@@ -398,7 +398,9 @@ export default class DocumentsStore extends BaseStore<Document> {
const results: SearchResult[] = compact(
res.data.map((result: SearchResult) => {
const document = this.data.get(result.document.id);
if (!document) return null;
if (!document) {
return null;
}
return {
ranking: result.ranking,
context: result.context,
@@ -450,7 +452,9 @@ export default class DocumentsStore extends BaseStore<Document> {
document: Document;
sharedTree?: NavigationNode;
}> => {
if (!options.prefetch) this.isFetching = true;
if (!options.prefetch) {
this.isFetching = true;
}
try {
const doc: Document | null | undefined =
@@ -540,7 +544,9 @@ export default class DocumentsStore extends BaseStore<Document> {
});
invariant(res && res.data, "Data should be available");
const collection = this.getCollectionForDocument(document);
if (collection) collection.refresh();
if (collection) {
collection.refresh();
}
this.addPolicies(res.policies);
return this.add(res.data);
};
@@ -635,7 +641,9 @@ export default class DocumentsStore extends BaseStore<Document> {
// Because the collection object contains the url and title
// we need to ensure they are updated there as well.
const collection = this.getCollectionForDocument(document);
if (collection) collection.updateDocument(document);
if (collection) {
collection.updateDocument(document);
}
return document;
}
@@ -656,7 +664,9 @@ export default class DocumentsStore extends BaseStore<Document> {
}
const collection = this.getCollectionForDocument(document);
if (collection) collection.refresh();
if (collection) {
collection.refresh();
}
}
@action
@@ -670,7 +680,9 @@ export default class DocumentsStore extends BaseStore<Document> {
this.addPolicies(res.policies);
});
const collection = this.getCollectionForDocument(document);
if (collection) collection.refresh();
if (collection) {
collection.refresh();
}
};
@action
@@ -692,7 +704,9 @@ export default class DocumentsStore extends BaseStore<Document> {
this.addPolicies(res.policies);
});
const collection = this.getCollectionForDocument(document);
if (collection) collection.refresh();
if (collection) {
collection.refresh();
}
};
@action
@@ -706,7 +720,9 @@ export default class DocumentsStore extends BaseStore<Document> {
this.addPolicies(res.policies);
});
const collection = this.getCollectionForDocument(document);
if (collection) collection.refresh();
if (collection) {
collection.refresh();
}
};
star = async (document: Document) => {

View File

@@ -48,7 +48,9 @@ export default class GroupsStore extends BaseStore<Group> {
const groups = filter(this.orderedData, (group) =>
groupIds.includes(group.id)
);
if (!query) return groups;
if (!query) {
return groups;
}
return queriedGroups(groups, query);
};
@@ -62,7 +64,9 @@ export default class GroupsStore extends BaseStore<Group> {
this.orderedData,
(group) => !groupIds.includes(group.id)
);
if (!query) return groups;
if (!query) {
return groups;
}
return queriedGroups(groups, query);
};
}

View File

@@ -39,7 +39,9 @@ export default class SharesStore extends BaseStore<Share> {
@action
async create(params: Record<string, any>) {
const item = this.getByDocumentId(params.documentId);
if (item) return item;
if (item) {
return item;
}
return super.create(params);
}
@@ -49,7 +51,9 @@ export default class SharesStore extends BaseStore<Share> {
options: Record<string, any> = {}
): Promise<any> {
const item = this.getByDocumentId(documentId);
if (item && !options.force) return item;
if (item && !options.force) {
return item;
}
this.isFetching = true;
try {
@@ -58,7 +62,9 @@ export default class SharesStore extends BaseStore<Share> {
apiVersion: 2,
});
if (isUndefined(res)) return;
if (isUndefined(res)) {
return;
}
invariant(res && res.data, "Data should be available");
this.addPolicies(res.policies);
return res.data.shares.map(this.add);
@@ -69,10 +75,14 @@ export default class SharesStore extends BaseStore<Share> {
getByDocumentParents = (documentId: string): Share | null | undefined => {
const document = this.rootStore.documents.get(documentId);
if (!document) return;
if (!document) {
return;
}
const collection = this.rootStore.collections.get(document.collectionId);
if (!collection) return;
if (!collection) {
return;
}
const parentIds = collection
.pathToDocument(documentId)

View File

@@ -16,7 +16,9 @@ export default class ToastsStore {
type: "info",
}
) => {
if (!message) return;
if (!message) {
return;
}
const lastToast = this.toasts.get(this.lastToastId);
if (lastToast && lastToast.message === message) {

View File

@@ -211,7 +211,9 @@ export default class UsersStore extends BaseStore<User> {
this.activeOrInvited,
(user) => !userIds.includes(user.id)
);
if (!query) return users;
if (!query) {
return users;
}
return queriedUsers(users, query);
};
@@ -224,7 +226,9 @@ export default class UsersStore extends BaseStore<User> {
const users = filter(this.activeOrInvited, (user) =>
userIds.includes(user.id)
);
if (!query) return users;
if (!query) {
return users;
}
return queriedUsers(users, query);
};
@@ -238,7 +242,9 @@ export default class UsersStore extends BaseStore<User> {
this.activeOrInvited,
(user) => !userIds.includes(user.id)
);
if (!query) return users;
if (!query) {
return users;
}
return queriedUsers(users, query);
};
@@ -251,7 +257,9 @@ export default class UsersStore extends BaseStore<User> {
const users = filter(this.activeOrInvited, (user) =>
userIds.includes(user.id)
);
if (!query) return users;
if (!query) {
return users;
}
return queriedUsers(users, query);
};

View File

@@ -28,7 +28,9 @@ export default class ViewsStore extends BaseStore<View> {
this.orderedData,
(view) => view.documentId === documentId && view.user.id === userId
);
if (!view) return;
if (!view) {
return;
}
view.touch();
}
}

View File

@@ -31,7 +31,9 @@ export function groupSettingsPath(): string {
}
export function collectionUrl(url: string, section?: string): string {
if (section) return `${url}/${section}`;
if (section) {
return `${url}/${section}`;
}
return url;
}
@@ -60,7 +62,9 @@ export function documentMoveUrl(doc: Document): string {
export function documentHistoryUrl(doc: Document, revisionId?: string): string {
let base = `${doc.url}/history`;
if (revisionId) base += `/${revisionId}`;
if (revisionId) {
base += `/${revisionId}`;
}
return base;
}

View File

@@ -1,7 +1,9 @@
import { parseDomain } from "@shared/utils/domains";
export function isInternalUrl(href: string) {
if (href[0] === "/") return true;
if (href[0] === "/") {
return true;
}
const outline = parseDomain(window.location.href);
const parsed = parseDomain(href);
@@ -19,7 +21,9 @@ export function isInternalUrl(href: string) {
}
export function isHash(href: string) {
if (href[0] === "#") return true;
if (href[0] === "#") {
return true;
}
try {
const outline = new URL(window.location.href);