Skip to content

Commit

Permalink
Merge branch 'main' into chore/event-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tommoor committed Oct 26, 2023
2 parents 1f731cf + afb5ccb commit b826ae1
Show file tree
Hide file tree
Showing 115 changed files with 680 additions and 1,271 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Expand Up @@ -13,5 +13,4 @@ app.json
crowdin.yml
build
docker-compose.yml
fakes3
node_modules
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -7,7 +7,7 @@ node_modules/*
npm-debug.log
stats.json
.DS_Store
fakes3/*
data/*
.idea
*.pem
*.key
Expand Down
23 changes: 17 additions & 6 deletions app/actions/definitions/developer.tsx
@@ -1,6 +1,6 @@
import { ToolsIcon, TrashIcon, UserIcon } from "outline-icons";
import * as React from "react";
import stores from "~/stores";
import { toast } from "sonner";
import { createAction } from "~/actions";
import { DeveloperSection } from "~/actions/sections";
import env from "~/env";
Expand All @@ -15,7 +15,7 @@ export const clearIndexedDB = createAction({
section: DeveloperSection,
perform: async ({ t }) => {
await deleteAllDatabases();
stores.toasts.showToast(t("IndexedDB cache deleted"));
toast.message(t("IndexedDB cache deleted"));
},
});

Expand All @@ -29,20 +29,31 @@ export const createTestUsers = createAction({

try {
await client.post("/developer.create_test_users", { count });
stores.toasts.showToast(`${count} test users created`);
toast.message(`${count} test users created`);
} catch (err) {
stores.toasts.showToast(err.message, { type: "error" });
toast.error(err.message);
}
},
});

export const createToast = createAction({
name: "Create toast",
section: DeveloperSection,
visible: () => env.ENVIRONMENT === "development",
perform: async () => {
toast.message("Hello world", {
duration: 30000,
});
},
});

export const toggleDebugLogging = createAction({
name: ({ t }) => t("Toggle debug logging"),
icon: <ToolsIcon />,
section: DeveloperSection,
perform: async ({ t }) => {
Logger.debugLoggingEnabled = !Logger.debugLoggingEnabled;
stores.toasts.showToast(
toast.message(
Logger.debugLoggingEnabled
? t("Debug logging enabled")
: t("Debug logging disabled")
Expand All @@ -56,7 +67,7 @@ export const developer = createAction({
icon: <ToolsIcon />,
iconInContextMenu: false,
section: DeveloperSection,
children: [clearIndexedDB, toggleDebugLogging, createTestUsers],
children: [clearIndexedDB, toggleDebugLogging, createToast, createTestUsers],
});

export const rootDeveloperActions = [developer];
65 changes: 24 additions & 41 deletions app/actions/definitions/documents.tsx
Expand Up @@ -25,6 +25,7 @@ import {
CommentIcon,
} from "outline-icons";
import * as React from "react";
import { toast } from "sonner";
import { ExportContentType, TeamPreference } from "@shared/types";
import { getEventFiles } from "@shared/utils/files";
import DocumentDelete from "~/scenes/DocumentDelete";
Expand Down Expand Up @@ -209,13 +210,10 @@ export const publishDocument = createAction({
await document.save(undefined, {
publish: true,
});
stores.toasts.showToast(
toast.success(
t("Published {{ documentName }}", {
documentName: document.noun,
}),
{
type: "success",
}
})
);
} else if (document) {
stores.dialogs.openModal({
Expand Down Expand Up @@ -248,16 +246,17 @@ export const unpublishDocument = createAction({
return;
}

await document.unpublish();
try {
await document.unpublish();

stores.toasts.showToast(
t("Unpublished {{ documentName }}", {
documentName: document.noun,
}),
{
type: "success",
}
);
toast.success(
t("Unpublished {{ documentName }}", {
documentName: document.noun,
})
);
} catch (err) {
toast.error(err.message);
}
},
});

Expand Down Expand Up @@ -287,9 +286,7 @@ export const subscribeDocument = createAction({

await document?.subscribe();

stores.toasts.showToast(t("Subscribed to document notifications"), {
type: "success",
});
toast.success(t("Subscribed to document notifications"));
},
});

Expand Down Expand Up @@ -319,9 +316,7 @@ export const unsubscribeDocument = createAction({

await document?.unsubscribe(currentUserId);

stores.toasts.showToast(t("Unsubscribed from document notifications"), {
type: "success",
});
toast.success(t("Unsubscribed from document notifications"));
},
});

Expand Down Expand Up @@ -360,15 +355,11 @@ export const downloadDocumentAsPDF = createAction({
return;
}

const id = stores.toasts.showToast(`${t("Exporting")}…`, {
type: "loading",
timeout: 30 * 1000,
});

const id = toast.loading(`${t("Exporting")}…`);
const document = stores.documents.get(activeDocumentId);
document
?.download(ExportContentType.Pdf)
.finally(() => id && stores.toasts.hideToast(id));
.finally(() => id && toast.dismiss(id));
},
});

Expand Down Expand Up @@ -479,12 +470,10 @@ export const pinDocumentToCollection = createAction({
const collection = stores.collections.get(activeCollectionId);

if (!collection || !location.pathname.startsWith(collection?.url)) {
stores.toasts.showToast(t("Pinned to collection"));
toast.success(t("Pinned to collection"));
}
} catch (err) {
stores.toasts.showToast(err.message, {
type: "error",
});
toast.error(err.message);
}
},
});
Expand Down Expand Up @@ -521,12 +510,10 @@ export const pinDocumentToHome = createAction({
await document?.pin();

if (location.pathname !== homePath()) {
stores.toasts.showToast(t("Pinned to home"));
toast.success(t("Pinned to home"));
}
} catch (err) {
stores.toasts.showToast(err.message, {
type: "error",
});
toast.error(err.message);
}
},
});
Expand Down Expand Up @@ -569,7 +556,7 @@ export const importDocument = createAction({
return false;
},
perform: ({ activeCollectionId, activeDocumentId, stores }) => {
const { documents, toasts } = stores;
const { documents } = stores;
const input = document.createElement("input");
input.type = "file";
input.accept = documents.importFileTypes.join(", ");
Expand All @@ -589,9 +576,7 @@ export const importDocument = createAction({
);
history.push(document.url);
} catch (err) {
toasts.showToast(err.message, {
type: "error",
});
toast.error(err.message);
throw err;
}
};
Expand Down Expand Up @@ -712,9 +697,7 @@ export const archiveDocument = createAction({
}

await document.archive();
stores.toasts.showToast(t("Document archived"), {
type: "success",
});
toast.success(t("Document archived"));
}
},
});
Expand Down
5 changes: 2 additions & 3 deletions app/actions/definitions/revisions.tsx
Expand Up @@ -2,6 +2,7 @@ import copy from "copy-to-clipboard";
import { LinkIcon, RestoreIcon } from "outline-icons";
import * as React from "react";
import { matchPath } from "react-router-dom";
import { toast } from "sonner";
import stores from "~/stores";
import { createAction } from "~/actions";
import { RevisionSection } from "~/actions/sections";
Expand Down Expand Up @@ -68,9 +69,7 @@ export const copyLinkToRevision = createAction({
copy(url, {
format: "text/plain",
onCopy: () => {
stores.toasts.showToast(t("Link copied"), {
type: "info",
});
toast.message(t("Link copied"));
},
});
},
Expand Down
5 changes: 2 additions & 3 deletions app/actions/index.ts
@@ -1,5 +1,6 @@
import flattenDeep from "lodash/flattenDeep";
import * as React from "react";
import { toast } from "sonner";
import { Optional } from "utility-types";
import { v4 as uuidv4 } from "uuid";
import {
Expand Down Expand Up @@ -77,9 +78,7 @@ export function actionToMenuItem(
try {
action.perform?.(context);
} catch (err) {
context.stores.toasts.showToast(err.message, {
type: "error",
});
toast.error(err.message);
}
},
selected: action.selected?.(context),
Expand Down
1 change: 1 addition & 0 deletions app/components/Avatar/Avatar.tsx
Expand Up @@ -5,6 +5,7 @@ import Initials from "./Initials";

export enum AvatarSize {
Small = 16,
Toast = 18,
Medium = 24,
Large = 32,
XLarge = 48,
Expand Down
5 changes: 2 additions & 3 deletions app/components/CollectionDeleteDialog.tsx
Expand Up @@ -2,12 +2,12 @@ import { observer } from "mobx-react";
import * as React from "react";
import { useTranslation, Trans } from "react-i18next";
import { useHistory } from "react-router-dom";
import { toast } from "sonner";
import Collection from "~/models/Collection";
import ConfirmationDialog from "~/components/ConfirmationDialog";
import Text from "~/components/Text";
import useCurrentTeam from "~/hooks/useCurrentTeam";
import useStores from "~/hooks/useStores";
import useToasts from "~/hooks/useToasts";
import { homePath } from "~/utils/routeHelpers";

type Props = {
Expand All @@ -18,7 +18,6 @@ type Props = {
function CollectionDeleteDialog({ collection, onSubmit }: Props) {
const team = useCurrentTeam();
const { ui } = useStores();
const { showToast } = useToasts();
const history = useHistory();
const { t } = useTranslation();

Expand All @@ -31,7 +30,7 @@ function CollectionDeleteDialog({ collection, onSubmit }: Props) {

await collection.delete();
onSubmit();
showToast(t("Collection deleted"), { type: "success" });
toast.success(t("Collection deleted"));
};

return (
Expand Down
11 changes: 3 additions & 8 deletions app/components/CollectionDescription.tsx
Expand Up @@ -3,6 +3,7 @@ import { observer } from "mobx-react";
import { transparentize } from "polished";
import * as React from "react";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";
import styled from "styled-components";
import { s } from "@shared/styles";
import Collection from "~/models/Collection";
Expand All @@ -13,15 +14,13 @@ import LoadingIndicator from "~/components/LoadingIndicator";
import NudeButton from "~/components/NudeButton";
import usePolicy from "~/hooks/usePolicy";
import useStores from "~/hooks/useStores";
import useToasts from "~/hooks/useToasts";

type Props = {
collection: Collection;
};

function CollectionDescription({ collection }: Props) {
const { collections } = useStores();
const { showToast } = useToasts();
const { t } = useTranslation();
const [isExpanded, setExpanded] = React.useState(false);
const [isEditing, setEditing] = React.useState(false);
Expand Down Expand Up @@ -59,15 +58,11 @@ function CollectionDescription({ collection }: Props) {
});
setDirty(false);
} catch (err) {
showToast(
t("Sorry, an error occurred saving the collection", {
type: "error",
})
);
toast.error(t("Sorry, an error occurred saving the collection"));
throw err;
}
}, 1000),
[collection, showToast, t]
[collection, t]
);

const handleChange = React.useCallback(
Expand Down
5 changes: 2 additions & 3 deletions app/components/CommentDeleteDialog.tsx
@@ -1,11 +1,11 @@
import { observer } from "mobx-react";
import * as React from "react";
import { useTranslation, Trans } from "react-i18next";
import { toast } from "sonner";
import Comment from "~/models/Comment";
import ConfirmationDialog from "~/components/ConfirmationDialog";
import Text from "~/components/Text";
import useStores from "~/hooks/useStores";
import useToasts from "~/hooks/useToasts";

type Props = {
comment: Comment;
Expand All @@ -14,7 +14,6 @@ type Props = {

function CommentDeleteDialog({ comment, onSubmit }: Props) {
const { comments } = useStores();
const { showToast } = useToasts();
const { t } = useTranslation();
const hasChildComments = comments.inThread(comment.id).length > 1;

Expand All @@ -23,7 +22,7 @@ function CommentDeleteDialog({ comment, onSubmit }: Props) {
await comment.delete();
onSubmit?.();
} catch (err) {
showToast(err.message, { type: "error" });
toast.error(err.message);
}
};

Expand Down

0 comments on commit b826ae1

Please sign in to comment.