From 0a5420395a2758af4c65edc038b7e7ac5672876a Mon Sep 17 00:00:00 2001 From: Jonathan Poltak Samosir Date: Tue, 23 Jul 2024 21:37:59 +0700 Subject: [PATCH] Only render "create new space" btn if input is valid space name --- .../ui/CollectionPicker/index.tsx | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/custom-lists/ui/CollectionPicker/index.tsx b/src/custom-lists/ui/CollectionPicker/index.tsx index 15a1cc16a5..6a82825e4a 100644 --- a/src/custom-lists/ui/CollectionPicker/index.tsx +++ b/src/custom-lists/ui/CollectionPicker/index.tsx @@ -40,6 +40,7 @@ import { runInBackground } from 'src/util/webextensionRPC' import { ListTrees } from '../list-trees' import { ListTreeToggleArrow } from '../list-trees/components/tree-toggle-arrow' import { TooltipBox } from '@worldbrain/memex-common/lib/common-ui/components/tooltip-box' +import { validateSpaceName } from '@worldbrain/memex-common/lib/utils/space-name-validation' export interface Props extends SpacePickerDependencies { showPageLinks?: boolean @@ -107,29 +108,11 @@ class SpacePicker extends StatefulUIElement< return false } - if ( - this.state.newEntryName?.length > 0 && - this.state.newEntryName[this.state.newEntryName?.length - 1] - ?.unifiedId === null - ) { - return true - } else { - return false - } - - // const otherLists = normalizedStateToArray(this.state.listEntries).map( - // (e) => ({ - // id: e.localId, - // name: e.name, - // }), - // ) - - // const newName = - // this.state.newEntryName?.[this.state.newEntryName.length - 1] - // ?.name ?? '' + const newName = + this.state.newEntryName?.[this.state.newEntryName.length - 1] + ?.name ?? '' - // const validSpaceName = validateSpaceName(newName, otherLists).valid - // return validSpaceName + return validateSpaceName(newName, []).valid } private get selectedCacheListIds(): string[] {