Changes based on code review

27e0905a1bf9943192c69c5fcb081882f5fa77ee

Wolfsblvt <wolfsblvt@gmail.com>

2 files changed, +14 -37Ignore whitespace
public/scripts/bookmarks.js+13 -37
@@ -31,6 +31,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '
3131import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js';
3232import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
3333import { createTagMapFromList } from './tags.js';
34+import { renderTemplateAsync } from './templates.js';
3435
3536import {
3637 getUniqueName,
@@ -59,7 +60,8 @@ async function getExistingChatNames() {
5960async function getBookmarkName({ forceName = null } = {}) {
6061 const chatNames = await getExistingChatNames();
6162
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);
6365 if (name === null) {
6466 return null;
6567 }
@@ -233,7 +235,8 @@ export async function createNewBookmark(mesId, { forceName = null } = {}) {
233235 */
234236export function updateBookmarkDisplay(mes, newBookmarkLink = null) {
235237 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')}`);
237240}
238241
239242async function backToMainChat() {
@@ -423,14 +426,6 @@ function registerBookmarksSlashCommands() {
423426 const branchName = await branchChat(mesId);
424427 return branchName ?? '';
425428 },
426- namedArgumentList: [
427- SlashCommandNamedArgument.fromProps({
428- name: 'mes',
429- description: 'Message ID',
430- typeList: [ARGUMENT_TYPE.NUMBER],
431- enumProvider: commonEnumProviders.messages(),
432- }),
433- ],
434429 unnamedArgumentList: [
435430 SlashCommandArgument.fromProps({
436431 description: 'Message ID',
@@ -524,14 +519,6 @@ function registerBookmarksSlashCommands() {
524519
525520 return checkPointName;
526521 },
527- namedArgumentList: [
528- SlashCommandNamedArgument.fromProps({
529- name: 'mes',
530- description: 'Message ID',
531- typeList: [ARGUMENT_TYPE.NUMBER],
532- enumProvider: commonEnumProviders.messages(),
533- }),
534- ],
535522 unnamedArgumentList: [
536523 SlashCommandArgument.fromProps({
537524 description: 'Message ID',
@@ -549,12 +536,12 @@ function registerBookmarksSlashCommands() {
549536 }));
550537 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
551538 name: 'checkpoint-exit',
552539 returns: 'The name of the chat exited to. Returns nullan empty string if not in a checkpoint chat.',
553540 callback: async () => {
554541 const mainChat = await backToMainChat();
555542 return mainChat ?? '';
556543 },
557544 helpString: 'Exit the checkpoint chat.<br />If not in a checkpoint chat, returns nullempty string.',
558545 }));
559546 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
560547 name: 'checkpoint-parent',
@@ -563,8 +550,8 @@ function registerBookmarksSlashCommands() {
563550 const mainChatName = getMainChatName();
564551 return mainChatName ?? '';
565552 },
566553 helpString: 'Get the name of the parent chat for this checkpoint.<br />If not in a checkpoint chat, returns nullempty string.',
567554 }));
568555 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
569556 name: 'checkpoint-get',
570557 returns: 'Name of the chat',
@@ -575,14 +562,6 @@ function registerBookmarksSlashCommands() {
575562 const checkPointName = chat[mesId].extra?.bookmark_link;
576563 return checkPointName ?? '';
577564 },
578- namedArgumentList: [
579- SlashCommandNamedArgument.fromProps({
580- name: 'mes',
581- description: 'Message ID',
582- typeList: [ARGUMENT_TYPE.NUMBER],
583- enumProvider: commonEnumProviders.messages(),
584- }),
585- ],
586565 unnamedArgumentList: [
587566 SlashCommandArgument.fromProps({
588567 description: 'Message ID',
@@ -601,12 +580,9 @@ function registerBookmarksSlashCommands() {
601580 returns: 'JSON array of all existing checkpoints in this chat, as an array',
602581 /** @param {{links?: string}} args @returns {Promise<string>} */
603582 callback: async (args, _) => {
604583 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- }
610586 return JSON.stringify(result);
611587 },
612588 namedArgumentList: [
@@ -634,7 +610,7 @@ export function initBookmarks() {
634610 $('#option_back_to_main').on('click', backToMainChat);
635611 $('#option_convert_to_group').on('click', convertSoloToGroupChat);
636612
637613 $(document).on('click', '.select_chat_block, .bookmark_link, .mes_bookmark', async function (e) {
638614 // If shift is held down, we are not following the bookmark, but creating a new one
639615 if (e.shiftKey) {
640616 var selectedMesId = $(this).closest('.mes').attr('mesid');
public/scripts/templates/createCheckpoint.html+1 -0
@@ -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