Skip to content

Commit

Permalink
fix(#16): fix lost post config after save post from posts list
Browse files Browse the repository at this point in the history
  • Loading branch information
laggage committed Jan 6, 2022
1 parent cb23569 commit d27a555
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/commands/posts-list/save-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { inputPostSettings } from '../../utils/input-post-settings';
import { searchPostsByTitle } from '../../services/search-post-by-title';
import * as path from 'path';
import { refreshPostsList } from './refresh-posts-list';
import { PostEditDto } from '../../models/post-edit-dto';

export const savePostFileToCnblogs = async (fileUri: Uri) => {
if (!fileUri || fileUri.scheme !== 'file') {
Expand All @@ -21,7 +22,7 @@ export const savePostFileToCnblogs = async (fileUri: Uri) => {
// const fileNameWithoutExt = path.basename(fileName, path.extname(fileName));
const postId = PostFileMapManager.getPostId(filePath);
if (postId && postId >= 0) {
await savePostToCnblogs((await postService.fetchPostEditDto(postId)).post);
await savePostToCnblogs(await postService.fetchPostEditDto(postId));
} else {
const options = [`新建博文`, `关联已有博文`];
const selected = await window.showInformationMessage(
Expand Down Expand Up @@ -84,15 +85,16 @@ export const saveLocalDraftToCnblogs = async (localDraft: LocalDraftFile) => {
}
Object.assign(post, userInputPostConfig);

if (!(await savePostToCnblogs(post, true))) {
if (!(await savePostToCnblogs(editDto, true))) {
return;
}
await PostFileMapManager.updateOrCreate(post.id, localDraft.filePath);
postsDataProvider.fireTreeDataChangedEvent(undefined);
await openPostFile(localDraft);
};

export const savePostToCnblogs = async (post: Post, isNewPost = false) => {
export const savePostToCnblogs = async (input: Post | PostEditDto, isNewPost = false) => {
const post = input instanceof PostEditDto ? input.post : (await postService.fetchPostEditDto(input.id)).post;
if (!post) {
return;
}
Expand Down
7 changes: 4 additions & 3 deletions src/services/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ export class PostService {
newPostTemplate = await this.fetchPostEditDto(-1);
}

return Object.assign({}, newPostTemplate, {
post: Object.assign({}, newPostTemplate.post),
} as PostEditDto);
return new PostEditDto(
Object.assign(new Post(), newPostTemplate.post),
Object.assign({}, newPostTemplate.config)
);
}
}

Expand Down

0 comments on commit d27a555

Please sign in to comment.