fix: First auto-save unfocuses document (#1046)
* fix: Autosave unfocuses document * Revert unneeded change * test: le fix * fix: Handle offline state fix: Untitled documents appear with empty titles * fix: Draft bubble roundness (yes, it doesnt belong here but see it, fix it)
This commit is contained in:
@@ -585,15 +585,14 @@ router.post('documents.unstar', auth(), async ctx => {
|
||||
|
||||
router.post('documents.create', auth(), async ctx => {
|
||||
const {
|
||||
title,
|
||||
text,
|
||||
title = '',
|
||||
text = '',
|
||||
publish,
|
||||
collectionId,
|
||||
parentDocumentId,
|
||||
index,
|
||||
} = ctx.body;
|
||||
ctx.assertUuid(collectionId, 'collectionId must be an uuid');
|
||||
ctx.assertPresent(text, 'text is required');
|
||||
if (parentDocumentId) {
|
||||
ctx.assertUuid(parentDocumentId, 'parentDocumentId must be an uuid');
|
||||
}
|
||||
|
||||
@@ -1039,22 +1039,6 @@ describe('#documents.create', async () => {
|
||||
expect(newDocument.collection.id).toBe(collection.id);
|
||||
});
|
||||
|
||||
it('should fallback to a default title', async () => {
|
||||
const { user, collection } = await seed();
|
||||
const res = await server.post('/api/documents.create', {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
collectionId: collection.id,
|
||||
title: ' ',
|
||||
text: ' ',
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.title).toBe('Untitled document');
|
||||
expect(body.data.text).toBe('# Untitled document');
|
||||
});
|
||||
|
||||
it('should not allow very long titles', async () => {
|
||||
const { user, collection } = await seed();
|
||||
const res = await server.post('/api/documents.create', {
|
||||
@@ -1183,25 +1167,6 @@ describe('#documents.update', async () => {
|
||||
expect(revisionRecords).toBe(prevRevisionRecords);
|
||||
});
|
||||
|
||||
it('should fallback to a default title', async () => {
|
||||
const { user, document } = await seed();
|
||||
|
||||
const res = await server.post('/api/documents.update', {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
id: document.id,
|
||||
title: ' ',
|
||||
text: ' ',
|
||||
lastRevision: document.revision,
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.title).toBe('Untitled document');
|
||||
expect(body.data.text).toBe('# Untitled document');
|
||||
});
|
||||
|
||||
it('should fail if document lastRevision does not match', async () => {
|
||||
const { user, document } = await seed();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import Revision from './Revision';
|
||||
const Op = Sequelize.Op;
|
||||
const Markdown = new MarkdownSerializer();
|
||||
const URL_REGEX = /^[a-zA-Z0-9-]*-([a-zA-Z0-9]{10,15})$/;
|
||||
const DEFAULT_TITLE = 'Untitled document';
|
||||
const DEFAULT_TITLE = 'Untitled';
|
||||
|
||||
slug.defaults.mode = 'rfc3986';
|
||||
const slugify = text =>
|
||||
@@ -55,10 +55,9 @@ const beforeSave = async doc => {
|
||||
// emoji in the title is split out for easier display
|
||||
doc.emoji = emoji;
|
||||
|
||||
// ensure document has a title
|
||||
// ensure documents have a title
|
||||
if (!title) {
|
||||
doc.title = DEFAULT_TITLE;
|
||||
doc.text = doc.text.replace(/^.*$/m, `# ${DEFAULT_TITLE}`);
|
||||
}
|
||||
|
||||
// add the current user as a collaborator on this doc
|
||||
|
||||
@@ -13,11 +13,6 @@ export default async function present(document: Document, options: ?Options) {
|
||||
...options,
|
||||
};
|
||||
|
||||
// For empty document content, return the title
|
||||
if (!document.text.trim()) {
|
||||
document.text = `# ${document.title}`;
|
||||
}
|
||||
|
||||
const data = {
|
||||
id: document.id,
|
||||
url: document.url,
|
||||
|
||||
Reference in New Issue
Block a user