From cef344c45c0c2a0de6b955325f7758d6ade921c9 Mon Sep 17 00:00:00 2001 From: AmbrishRamachandiran Date: Fri, 4 Aug 2023 09:40:23 +0530 Subject: [PATCH] Limit the use of the same shortcut name and url when adding a shortcut fixed review changes Signed-off-by: AmbrishRamachandiran --- plugins/shortcuts/src/ShortcutForm.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/shortcuts/src/ShortcutForm.tsx b/plugins/shortcuts/src/ShortcutForm.tsx index 4384f1c061..6085c6c182 100644 --- a/plugins/shortcuts/src/ShortcutForm.tsx +++ b/plugins/shortcuts/src/ShortcutForm.tsx @@ -15,6 +15,7 @@ */ import React, { useEffect } from 'react'; +import useObservable from 'react-use/lib/useObservable'; import { useForm, SubmitHandler, Controller } from 'react-hook-form'; import { Button, @@ -53,7 +54,10 @@ export const ShortcutForm = ({ }: Props) => { const classes = useStyles(); const shortcutApi = useApi(shortcutsApiRef); - const shortcutData = shortcutApi.get(); + const shortcutData = useObservable( + shortcutApi.shortcut$(), + shortcutApi.get(), + ); const { handleSubmit, reset, @@ -67,13 +71,13 @@ export const ShortcutForm = ({ }, }); - const titleIsUnique = async (title: string) => { + const titleIsUnique = (title: string) => { if (shortcutData.some(shortcutTitle => shortcutTitle.title === title)) return 'A shortcut with this title already exists'; return true; }; - const urlIsUnique = async (url: string) => { + const urlIsUnique = (url: string) => { if (shortcutData.some(shortcutUrl => shortcutUrl.url === url)) return 'A shortcut with this url already exists'; return true;