Changes based on code review
| @@ -31,6 +31,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from ' | ||
| 31 | 31 | import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js'; |
| 32 | 32 | import { SlashCommandParser } from './slash-commands/SlashCommandParser.js'; |
| 33 | 33 | import { createTagMapFromList } from './tags.js'; |
| 34 | +import { renderTemplateAsync } from './templates.js'; | |
| 34 | 35 | |
| 35 | 36 | import { |
| 36 | 37 | getUniqueName, |
| @@ -59,7 +60,8 @@ async function getExistingChatNames() { | ||
| 59 | 60 | async function getBookmarkName({ forceName = null } = {}) { |
| 60 | 61 | const chatNames = await getExistingChatNames(); |
| 61 | 62 | |
| 62 | - let name = forceName || await Popup.show.input('Create Checkpoint', '<span class="margin-right-10px">Enter Checkpoint Name:</span><small>(Leave empty to auto-generate)</small>'); | |
| 63 | + const body = await renderTemplateAsync('createCheckpoint'); | |
| 64 | + let name = forceName || await Popup.show.input('Create Checkpoint', body); | |
| 63 | 65 | if (name === null) { |
| 64 | 66 | return null; |
| 65 | 67 | } |
| @@ -233,7 +235,8 @@ export async function createNewBookmark(mesId, { forceName = null } = {}) { | ||
| 233 | 235 | */ |
| 234 | 236 | export function updateBookmarkDisplay(mes, newBookmarkLink = null) { |
| 235 | 237 | newBookmarkLink && mes.attr('bookmark_link', newBookmarkLink); |
| 236 | - mes.find('.mes_bookmark').attr('title', `Checkpoint\n${mes.attr('bookmark_link')}\n\n${mes.find('.mes_bookmark').data('tooltip')}`); | |
| 238 | + const bookmarkFlag = mes.find('.mes_bookmark'); | |
| 239 | + bookmarkFlag.attr('title', `Checkpoint\n${mes.attr('bookmark_link')}\n\n${bookmarkFlag.data('tooltip')}`); | |
| 237 | 240 | } |
| 238 | 241 | |
| 239 | 242 | async function backToMainChat() { |
| @@ -423,14 +426,6 @@ function registerBookmarksSlashCommands() { | ||
| 423 | 426 | const branchName = await branchChat(mesId); |
| 424 | 427 | return branchName ?? ''; |
| 425 | 428 | }, |
| 426 | - namedArgumentList: [ | |
| 427 | - SlashCommandNamedArgument.fromProps({ | |
| 428 | - name: 'mes', | |
| 429 | - description: 'Message ID', | |
| 430 | - typeList: [ARGUMENT_TYPE.NUMBER], | |
| 431 | - enumProvider: commonEnumProviders.messages(), | |
| 432 | - }), | |
| 433 | - ], | |
| 434 | 429 | unnamedArgumentList: [ |
| 435 | 430 | SlashCommandArgument.fromProps({ |
| 436 | 431 | description: 'Message ID', |
| @@ -524,14 +519,6 @@ function registerBookmarksSlashCommands() { | ||
| 524 | 519 | |
| 525 | 520 | return checkPointName; |
| 526 | 521 | }, |
| 527 | - namedArgumentList: [ | |
| 528 | - SlashCommandNamedArgument.fromProps({ | |
| 529 | - name: 'mes', | |
| 530 | - description: 'Message ID', | |
| 531 | - typeList: [ARGUMENT_TYPE.NUMBER], | |
| 532 | - enumProvider: commonEnumProviders.messages(), | |
| 533 | - }), | |
| 534 | - ], | |
| 535 | 522 | unnamedArgumentList: [ |
| 536 | 523 | SlashCommandArgument.fromProps({ |
| 537 | 524 | description: 'Message ID', |
| @@ -549,12 +536,12 @@ function registerBookmarksSlashCommands() { | ||
| 549 | 536 | })); |
| 550 | 537 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 551 | 538 | name: 'checkpoint-exit', |
| 552 | 539 | returns: 'The name of the chat exited to. Returns nullan empty string if not in a checkpoint chat.', |
| 553 | 540 | callback: async () => { |
| 554 | 541 | const mainChat = await backToMainChat(); |
| 555 | 542 | return mainChat ?? ''; |
| 556 | 543 | }, |
| 557 | 544 | helpString: 'Exit the checkpoint chat.<br />If not in a checkpoint chat, returns nullempty string.', |
| 558 | 545 | })); |
| 559 | 546 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 560 | 547 | name: 'checkpoint-parent', |
| @@ -563,8 +550,8 @@ function registerBookmarksSlashCommands() { | ||
| 563 | 550 | const mainChatName = getMainChatName(); |
| 564 | 551 | return mainChatName ?? ''; |
| 565 | 552 | }, |
| 566 | 553 | helpString: 'Get the name of the parent chat for this checkpoint.<br />If not in a checkpoint chat, returns nullempty string.', |
| 567 | 554 | })); |
| 568 | 555 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 569 | 556 | name: 'checkpoint-get', |
| 570 | 557 | returns: 'Name of the chat', |
| @@ -575,14 +562,6 @@ function registerBookmarksSlashCommands() { | ||
| 575 | 562 | const checkPointName = chat[mesId].extra?.bookmark_link; |
| 576 | 563 | return checkPointName ?? ''; |
| 577 | 564 | }, |
| 578 | - namedArgumentList: [ | |
| 579 | - SlashCommandNamedArgument.fromProps({ | |
| 580 | - name: 'mes', | |
| 581 | - description: 'Message ID', | |
| 582 | - typeList: [ARGUMENT_TYPE.NUMBER], | |
| 583 | - enumProvider: commonEnumProviders.messages(), | |
| 584 | - }), | |
| 585 | - ], | |
| 586 | 565 | unnamedArgumentList: [ |
| 587 | 566 | SlashCommandArgument.fromProps({ |
| 588 | 567 | description: 'Message ID', |
| @@ -601,12 +580,9 @@ function registerBookmarksSlashCommands() { | ||
| 601 | 580 | returns: 'JSON array of all existing checkpoints in this chat, as an array', |
| 602 | 581 | /** @param {{links?: string}} args @returns {Promise<string>} */ |
| 603 | 582 | callback: async (args, _) => { |
| 604 | 583 | const result = [];Object.entries(chat) |
| 605 | - for (const mesId in chat) { | |
| 584 | + .filter(([_, message]) => message.extra?.bookmark_link) | |
| 606 | - if (chat[mesId].extra?.bookmark_link) { | |
| 585 | + .map(([mesId, message]) => args.links ? message.extra.bookmark_link : Number(mesId)); | |
| 607 | - result.push(args.links ? chat[mesId].extra.bookmark_link : Number(mesId)); | |
| 608 | - } | |
| 609 | - } | |
| 610 | 586 | return JSON.stringify(result); |
| 611 | 587 | }, |
| 612 | 588 | namedArgumentList: [ |
| @@ -634,7 +610,7 @@ export function initBookmarks() { | ||
| 634 | 610 | $('#option_back_to_main').on('click', backToMainChat); |
| 635 | 611 | $('#option_convert_to_group').on('click', convertSoloToGroupChat); |
| 636 | 612 | |
| 637 | 613 | $(document).on('click', '.select_chat_block, .bookmark_link, .mes_bookmark', async function (e) { |
| 638 | 614 | // If shift is held down, we are not following the bookmark, but creating a new one |
| 639 | 615 | if (e.shiftKey) { |
| 640 | 616 | var selectedMesId = $(this).closest('.mes').attr('mesid'); |
| @@ -0,0 +1 @@ | ||
| 1 | +<span class="margin-right-10px">Enter Checkpoint Name:</span><small>(Leave empty to auto-generate)</small> | |
| 1 | \ No newline at end of file | |