리펙토링 - 전체 프로젝트 코드 (Codex)
This commit is contained in:
+9
-20
@@ -3,6 +3,8 @@ import { showLoading, hideLoading, setStatus, showToast } from './ui.js';
|
||||
import { renderGrid } from './grid.js';
|
||||
import * as history from './history.js';
|
||||
import { openModal, closeModal } from './modal.js';
|
||||
import { renderTextList } from './utils/dom.js';
|
||||
import { buildSequentialName, getNameFormat } from './utils/file-names.js';
|
||||
|
||||
const inputPrefix = document.getElementById('input-prefix');
|
||||
const inputDigits = document.getElementById('input-digits');
|
||||
@@ -28,8 +30,8 @@ renameConfirmModal.addEventListener('modal:closed', () => {
|
||||
|
||||
export async function doRename() {
|
||||
if (!state.files.length || !state.currentFolder) return;
|
||||
const prefix = inputPrefix.value.trim() || 'photo';
|
||||
const digits = Math.max(1, Math.min(6, parseInt(inputDigits.value) || 3));
|
||||
const { prefix, digits } = getNameFormat(inputPrefix, inputDigits);
|
||||
const format = { prefix, digits };
|
||||
|
||||
const selectedArr = [...state.selectedIdxs].sort((a, b) => a - b);
|
||||
const filesToRename = selectedArr.length > 0
|
||||
@@ -43,26 +45,17 @@ export async function doRename() {
|
||||
const unselectedNames = new Set(
|
||||
state.files.filter((_, i) => !state.selectedIdxs.has(i)).map(f => f.name)
|
||||
);
|
||||
const newNames = filesToRename.map((f, i) => {
|
||||
const ext = f.name.split('.').pop().toLowerCase();
|
||||
return `${prefix}_${String(i + 1).padStart(digits, '0')}.${ext}`;
|
||||
});
|
||||
const newNames = filesToRename.map((f, i) => buildSequentialName(f.name, i, format));
|
||||
const conflicting = newNames.filter(n => unselectedNames.has(n));
|
||||
if (conflicting.length) {
|
||||
renameConflictList.replaceChildren(...conflicting.map(n => {
|
||||
const li = document.createElement('li');
|
||||
li.textContent = n;
|
||||
return li;
|
||||
}));
|
||||
renderTextList(renameConflictList, conflicting);
|
||||
openModal(renameConflictModal);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const examples = filesToRename.slice(0, 3).map((f, i) => {
|
||||
const ext = f.name.split('.').pop().toLowerCase();
|
||||
return `${f.name} → ${prefix}_${String(i + 1).padStart(digits, '0')}.${ext}`;
|
||||
});
|
||||
const examples = filesToRename.slice(0, 3)
|
||||
.map((f, i) => `${f.name} → ${buildSequentialName(f.name, i, format)}`);
|
||||
const more = filesToRename.length > 3 ? `... 외 ${filesToRename.length - 3}개` : '';
|
||||
|
||||
const confirmed = await showRenameConfirm({
|
||||
@@ -111,11 +104,7 @@ function showRenameConfirm({ count, examples, more, isPartial }) {
|
||||
|
||||
const items = [...examples];
|
||||
if (more) items.push(more);
|
||||
renameConfirmList.replaceChildren(...items.map(text => {
|
||||
const li = document.createElement('li');
|
||||
li.textContent = text;
|
||||
return li;
|
||||
}));
|
||||
renderTextList(renameConfirmList, items);
|
||||
|
||||
openModal(renameConfirmModal);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user