flow(function* copyPost(copyId) { // @ts-ignore const post = yield self.getPost(copyId); const newDraftRef = firestore.collection("posts").doc(); const id = newDraftRef.id; const now = moment.now(); const newPost = { id, changed: now, status: PostStatus.Draft, draft: { ...post.draft, title: `${post.draft.title} (Copy)`, changed: now } }; // @ts-ignore self.posts.set(id, newPost); yield newDraftRef.set(newPost); return id; })
flow(function* saveNewPost(title, text) { const newDraftRef = firestore.collection("posts").doc(); const id = newDraftRef.id; const now = moment.now(); const currentAuthor = self.blog.authors.currentAuthor; const newPost = { id, changed: now, status: PostStatus.Draft, draft: { title: title || "(Untitled)", text: text || "", changed: now, meta: createMeta({ author: currentAuthor ? currentAuthor.id : "" }) } }; // @ts-ignore self.posts.set(id, newPost); yield newDraftRef.set(newPost); return id; })