(
folders: ReturnType<
ReturnType<typeof useNotesStorage>['folders']['getFolders']
>,
parentId: number | null,
name: string,
)
| 26 | } |
| 27 | |
| 28 | function getUniqueFolderName( |
| 29 | folders: ReturnType< |
| 30 | ReturnType<typeof useNotesStorage>['folders']['getFolders'] |
| 31 | >, |
| 32 | parentId: number | null, |
| 33 | name: string, |
| 34 | ): string { |
| 35 | const siblingNames = new Set( |
| 36 | folders |
| 37 | .filter(folder => folder.parentId === parentId) |
| 38 | .map(folder => folder.name.toLowerCase()), |
| 39 | ) |
| 40 | |
| 41 | if (!siblingNames.has(name.toLowerCase())) { |
| 42 | return name |
| 43 | } |
| 44 | |
| 45 | for (let suffix = 1; suffix <= 10_000; suffix += 1) { |
| 46 | const candidate = `${name} ${suffix}` |
| 47 | if (!siblingNames.has(candidate.toLowerCase())) { |
| 48 | return candidate |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | return `${name} ${Date.now()}` |
| 53 | } |
| 54 | |
| 55 | function getUniqueNoteName( |
| 56 | notes: ReturnType<ReturnType<typeof useNotesStorage>['notes']['getNotes']>, |
no outgoing calls
no test coverage detected