Fix checkpoint create auto generate (and more)
- Fix empty checkpoint name on mes click to auto generate - Change /checkpoint-create to not require name and auto generate - Fix popup input type returning empty string instead of null on empty input field
This commit is contained in:
parent
d082c2f14d
commit
73c14711e1
|
@ -61,11 +61,9 @@ async function getBookmarkName({ isReplace = false, forceName = null } = {}) {
|
||||||
const chatNames = await getExistingChatNames();
|
const chatNames = await getExistingChatNames();
|
||||||
|
|
||||||
const body = await renderTemplateAsync('createCheckpoint', { isReplace: isReplace });
|
const body = await renderTemplateAsync('createCheckpoint', { isReplace: isReplace });
|
||||||
let name = forceName || await Popup.show.input('Create Checkpoint', body);
|
let name = forceName ?? await Popup.show.input('Create Checkpoint', body);
|
||||||
if (name === null) {
|
// Special handling for confirmed empty input (=> auto-generate name)
|
||||||
return null;
|
if (name === '') {
|
||||||
}
|
|
||||||
else if (name === '') {
|
|
||||||
for (let i = chatNames.length; i < 1000; i++) {
|
for (let i = chatNames.length; i < 1000; i++) {
|
||||||
name = bookmarkNameToken + i;
|
name = bookmarkNameToken + i;
|
||||||
if (!chatNames.includes(name)) {
|
if (!chatNames.includes(name)) {
|
||||||
|
@ -73,6 +71,9 @@ async function getBookmarkName({ isReplace = false, forceName = null } = {}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!name) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return `${name} - ${humanizedDateTime()}`;
|
return `${name} - ${humanizedDateTime()}`;
|
||||||
}
|
}
|
||||||
|
@ -447,8 +448,8 @@ function registerBookmarksSlashCommands() {
|
||||||
const mesId = Number(args.mesId ?? getLastMessageId());
|
const mesId = Number(args.mesId ?? getLastMessageId());
|
||||||
if (!validateMessageId(mesId, 'Create Checkpoint')) return '';
|
if (!validateMessageId(mesId, 'Create Checkpoint')) return '';
|
||||||
|
|
||||||
if (!text || typeof text !== 'string') {
|
if (typeof text !== 'string') {
|
||||||
toastr.warning('Checkpoint name must be provided', 'Create Checkpoint');
|
toastr.warning('Checkpoint name must be a string or empty', 'Create Checkpoint');
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,12 +468,12 @@ function registerBookmarksSlashCommands() {
|
||||||
SlashCommandArgument.fromProps({
|
SlashCommandArgument.fromProps({
|
||||||
description: 'Checkpoint name',
|
description: 'Checkpoint name',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
isRequired: true,
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
helpString: `
|
helpString: `
|
||||||
<div>
|
<div>
|
||||||
Create a new checkpoint for the selected message with the provided name. If no message id is provided, will use the last message.
|
Create a new checkpoint for the selected message with the provided name. If no message id is provided, will use the last message.<br />
|
||||||
|
Leave the checkpoint name empty to auto-generate one.
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
A created checkpoint will be permanently linked with the message.<br />
|
A created checkpoint will be permanently linked with the message.<br />
|
||||||
|
|
|
@ -83,6 +83,9 @@ const showPopupHelper = {
|
||||||
const content = PopupUtils.BuildTextWithHeader(header, text);
|
const content = PopupUtils.BuildTextWithHeader(header, text);
|
||||||
const popup = new Popup(content, POPUP_TYPE.INPUT, defaultValue, popupOptions);
|
const popup = new Popup(content, POPUP_TYPE.INPUT, defaultValue, popupOptions);
|
||||||
const value = await popup.show();
|
const value = await popup.show();
|
||||||
|
// Return values: If empty string, we explicitly handle that as returning that empty string as "success" provided.
|
||||||
|
// Otherwise, all non-truthy values (false, null, undefined) are treated as "cancel" and return null.
|
||||||
|
if (value === '') return '';
|
||||||
return value ? String(value) : null;
|
return value ? String(value) : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue