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 '
31import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js';31import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js';
32import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';32import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
33import { createTagMapFromList } from './tags.js';33import { createTagMapFromList } from './tags.js';
34import { renderTemplateAsync } from './templates.js';
3435
35import {36import {
36 getUniqueName,37 getUniqueName,
@@ -59,7 +60,8 @@ async function getExistingChatNames() {
59async function getBookmarkName({ forceName = null } = {}) {60async function getBookmarkName({ forceName = null } = {}) {
60 const chatNames = await getExistingChatNames();61 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);
63 if (name === null) {65 if (name === null) {
64 return null;66 return null;
65 }67 }
@@ -233,7 +235,8 @@ export async function createNewBookmark(mesId, { forceName = null } = {}) {
233 */235 */
234export function updateBookmarkDisplay(mes, newBookmarkLink = null) {236export function updateBookmarkDisplay(mes, newBookmarkLink = null) {
235 newBookmarkLink && mes.attr('bookmark_link', newBookmarkLink);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}
238241
239async function backToMainChat() {242async function backToMainChat() {
@@ -423,14 +426,6 @@ function registerBookmarksSlashCommands() {
423 const branchName = await branchChat(mesId);426 const branchName = await branchChat(mesId);
424 return branchName ?? '';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 unnamedArgumentList: [429 unnamedArgumentList: [
435 SlashCommandArgument.fromProps({430 SlashCommandArgument.fromProps({
436 description: 'Message ID',431 description: 'Message ID',
@@ -524,14 +519,6 @@ function registerBookmarksSlashCommands() {
524519
525 return checkPointName;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 unnamedArgumentList: [522 unnamedArgumentList: [
536 SlashCommandArgument.fromProps({523 SlashCommandArgument.fromProps({
537 description: 'Message ID',524 description: 'Message ID',
@@ -549,12 +536,12 @@ function registerBookmarksSlashCommands() {
549 }));536 }));
550 SlashCommandParser.addCommandObject(SlashCommand.fromProps({537 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
551 name: 'checkpoint-exit',538 name: 'checkpoint-exit',
552 returns: 'The name of the chat exited to. Returns null if not in a checkpoint chat.',539 returns: 'The name of the chat exited to. Returns an empty string if not in a checkpoint chat.',
553 callback: async () => {540 callback: async () => {
554 const mainChat = await backToMainChat();541 const mainChat = await backToMainChat();
555 return mainChat ?? '';542 return mainChat ?? '';
556 },543 },
557 helpString: 'Exit the checkpoint chat.<br />If not in a checkpoint chat, returns null.',544 helpString: 'Exit the checkpoint chat.<br />If not in a checkpoint chat, returns empty string.',
558 }));545 }));
559 SlashCommandParser.addCommandObject(SlashCommand.fromProps({546 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
560 name: 'checkpoint-parent',547 name: 'checkpoint-parent',
@@ -563,8 +550,8 @@ function registerBookmarksSlashCommands() {
563 const mainChatName = getMainChatName();550 const mainChatName = getMainChatName();
564 return mainChatName ?? '';551 return mainChatName ?? '';
565 },552 },
566 helpString: 'Get the name of the parent chat for this checkpoint. If not in a checkpoint chat, returns null.',553 helpString: 'Get the name of the parent chat for this checkpoint.<br />If not in a checkpoint chat, returns empty string.',
567 }))554 }));
568 SlashCommandParser.addCommandObject(SlashCommand.fromProps({555 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
569 name: 'checkpoint-get',556 name: 'checkpoint-get',
570 returns: 'Name of the chat',557 returns: 'Name of the chat',
@@ -575,14 +562,6 @@ function registerBookmarksSlashCommands() {
575 const checkPointName = chat[mesId].extra?.bookmark_link;562 const checkPointName = chat[mesId].extra?.bookmark_link;
576 return checkPointName ?? '';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 unnamedArgumentList: [565 unnamedArgumentList: [
587 SlashCommandArgument.fromProps({566 SlashCommandArgument.fromProps({
588 description: 'Message ID',567 description: 'Message ID',
@@ -601,12 +580,9 @@ function registerBookmarksSlashCommands() {
601 returns: 'JSON array of all existing checkpoints in this chat, as an array',580 returns: 'JSON array of all existing checkpoints in this chat, as an array',
602 /** @param {{links?: string}} args @returns {Promise<string>} */581 /** @param {{links?: string}} args @returns {Promise<string>} */
603 callback: async (args, _) => {582 callback: async (args, _) => {
604 const result = [];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 return JSON.stringify(result);586 return JSON.stringify(result);
611 },587 },
612 namedArgumentList: [588 namedArgumentList: [
@@ -634,7 +610,7 @@ export function initBookmarks() {
634 $('#option_back_to_main').on('click', backToMainChat);610 $('#option_back_to_main').on('click', backToMainChat);
635 $('#option_convert_to_group').on('click', convertSoloToGroupChat);611 $('#option_convert_to_group').on('click', convertSoloToGroupChat);
636612
637 $(document).on('click', '.select_chat_block, .bookmark_link, .mes_bookmark', async function (e) {613 $(document).on('click', '.select_chat_block, .mes_bookmark', async function (e) {
638 // If shift is held down, we are not following the bookmark, but creating a new one614 // If shift is held down, we are not following the bookmark, but creating a new one
639 if (e.shiftKey) {615 if (e.shiftKey) {
640 var selectedMesId = $(this).closest('.mes').attr('mesid');616 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>
\ No newline at end of file1 \ No newline at end of file