Skip to content

Commit f2ade59

Browse files
committed
feat: support select is to post publish
1 parent c615624 commit f2ade59

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/utils/input-post-settings.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@ class AccessPermissionPickItem implements QuickPickItem {
3434
constructor(public id: AccessPermission, public label: string) {}
3535
}
3636

37-
type PostSettingsType = 'categoryIds' | 'tags' | 'description' | 'password' | 'accessPermission';
37+
type PostSettingsType = 'categoryIds' | 'tags' | 'description' | 'password' | 'accessPermission' | 'isPublished';
3838
type PostSettingsDto = Pick<BlogPost, PostSettingsType>;
3939

40-
const defaultSteps: PostSettingsType[] = ['accessPermission', 'description', 'categoryIds', 'tags', 'password'];
40+
const defaultSteps: PostSettingsType[] = [
41+
'accessPermission',
42+
'description',
43+
'categoryIds',
44+
'tags',
45+
'password',
46+
'isPublished',
47+
];
4148

4249
const parseTagNames = (value: string) => {
4350
return value.split(/[,]/).filter(t => !!t);
@@ -172,12 +179,34 @@ export const inputPostSettings = async (
172179
configuredPost.password = value ?? '';
173180
return calculateNextStep();
174181
};
182+
// 是否发布
183+
const inputIsPublished = async (input: MultiStepInput) => {
184+
calculateStepNumber('isPublished');
185+
const items = [{ label: '是' } as QuickPickItem, { label: '否' } as QuickPickItem];
186+
const picked = await input.showQuickPick({
187+
items: items,
188+
title: state.title,
189+
step: state.step++,
190+
totalSteps: state.totalSteps,
191+
placeholder: '<必选>是否发布',
192+
activeItems: configuredPost.isPublished ? [items[0]] : [items[1]],
193+
buttons: [],
194+
canSelectMany: false,
195+
shouldResume: () => Promise.resolve(false),
196+
});
197+
if (picked) {
198+
configuredPost.isPublished = picked === items[0];
199+
}
200+
201+
return calculateNextStep();
202+
};
175203
map = [
176204
['accessPermission', inputAccessPermission],
177205
['categoryIds', inputCategory],
178206
['password', inputPassword],
179207
['description', inputDescription],
180208
['tags', inputTags],
209+
['isPublished', inputIsPublished],
181210
];
182211

183212
await MultiStepInput.run(calculateNextStep()!);

0 commit comments

Comments
 (0)