* Migrations, models, commands * ui * Move starred hint to location state * lint * tsc * refactor * Add collection empty state in expanded sidebar * Add empty placeholder within starred collections * Drag and drop improves, Relative refactor * fix: Starring untitled draft leaves empty space * fix: Creating draft in starred collection shouldnt open main * fix: Dupe drop cursor * Final fixes * fix: Canonical redirect replaces starred location state * fix: Don't show reorder cursor at the top of collection with no permission to edit when dragging
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import { observer } from "mobx-react";
|
||
import queryString from "query-string";
|
||
import * as React from "react";
|
||
import { useEffect } from "react";
|
||
import { useTranslation } from "react-i18next";
|
||
import { useHistory, useLocation, useRouteMatch } from "react-router-dom";
|
||
import CenteredContent from "~/components/CenteredContent";
|
||
import Flex from "~/components/Flex";
|
||
import PlaceholderDocument from "~/components/PlaceholderDocument";
|
||
import useStores from "~/hooks/useStores";
|
||
import useToasts from "~/hooks/useToasts";
|
||
import { editDocumentUrl } from "~/utils/routeHelpers";
|
||
|
||
function DocumentNew() {
|
||
const history = useHistory();
|
||
const location = useLocation();
|
||
const match = useRouteMatch<{ id?: string }>();
|
||
const { t } = useTranslation();
|
||
const { documents, collections } = useStores();
|
||
const { showToast } = useToasts();
|
||
const id = match.params.id || "";
|
||
|
||
useEffect(() => {
|
||
async function createDocument() {
|
||
const params = queryString.parse(location.search);
|
||
|
||
try {
|
||
const collection = await collections.fetch(id);
|
||
const document = await documents.create({
|
||
collectionId: collection.id,
|
||
parentDocumentId: params.parentDocumentId?.toString(),
|
||
templateId: params.templateId?.toString(),
|
||
template: params.template === "true" ? true : false,
|
||
title: "",
|
||
text: "",
|
||
});
|
||
history.replace(editDocumentUrl(document), location.state);
|
||
} catch (err) {
|
||
showToast(t("Couldn’t create the document, try again?"), {
|
||
type: "error",
|
||
});
|
||
history.goBack();
|
||
}
|
||
}
|
||
|
||
createDocument();
|
||
});
|
||
|
||
return (
|
||
<Flex column auto>
|
||
<CenteredContent>
|
||
<PlaceholderDocument />
|
||
</CenteredContent>
|
||
</Flex>
|
||
);
|
||
}
|
||
|
||
export default observer(DocumentNew);
|