Address feedback

This commit is contained in:
Daniel Espino García 2022-03-23 16:11:58 +01:00
parent 7bb37297bd
commit 7382c1f4fc
4 changed files with 24 additions and 5 deletions

View file

@ -205,6 +205,10 @@ export const fetchCommands = async (serverUrl: string, teamId: string) => {
let client: Client;
try {
client = NetworkManager.getClient(serverUrl);
} catch (error) {
return {error: error as ClientErrorProps};
}
try {
return {commands: await client.getCommandsList(teamId)};
} catch (error) {
return {error: error as ClientErrorProps};
@ -215,6 +219,11 @@ export const fetchSuggestions = async (serverUrl: string, term: string, teamId:
let client: Client;
try {
client = NetworkManager.getClient(serverUrl);
} catch (error) {
return {error: error as ClientErrorProps};
}
try {
return {suggestions: await client.getCommandAutocompleteSuggestionsList(term, teamId, channelId, rootId)};
} catch (error) {
return {error: error as ClientErrorProps};

View file

@ -73,10 +73,7 @@ export async function getChannelSuggestions(channels?: Channel[]): Promise<Autoc
Hint: '',
IconData: '',
}];
if (!channels) {
return notFoundSuggestion;
}
if (!channels.length) {
if (!channels?.length) {
return notFoundSuggestion;
}

View file

@ -92,6 +92,7 @@ const SlashSuggestion = ({
const serverUrl = useServerUrl();
const appCommandParser = useRef<AppCommandParser>(new AppCommandParser(serverUrl, intl, channelId, currentTeamId, rootId, theme));
const mounted = useRef(false);
const [noResultsTerm, setNoResultsTerm] = useState<string|null>(null);
const [dataSource, setDataSource] = useState<AutocompleteSuggestion[]>(emptySuggestionList);
const [commands, setCommands] = useState<Command[]>();
@ -113,6 +114,7 @@ const SlashSuggestion = ({
updateSuggestions(emptySuggestionList);
} else if (res.suggestions.length === 0) {
updateSuggestions(emptySuggestionList);
setNoResultsTerm(term);
} else {
updateSuggestions(res.suggestions);
}
@ -182,6 +184,7 @@ const SlashSuggestion = ({
useEffect(() => {
if (value[0] !== '/') {
runFetch.cancel();
setNoResultsTerm(null);
updateSuggestions(emptySuggestionList);
return;
}
@ -200,6 +203,11 @@ const SlashSuggestion = ({
if (value.indexOf(' ') === -1) {
runFetch.cancel();
showBaseCommands(value);
setNoResultsTerm(null);
return;
}
if (noResultsTerm && value.startsWith(noResultsTerm)) {
return;
}

View file

@ -122,7 +122,12 @@ const SlashSuggestionItem = ({
} else if (icon.startsWith('data:')) {
if (icon.startsWith('data:image/svg+xml')) {
// TODO: What base64 library should we use? Security implications on doing things like this?
const xml = ''; // base64.decode(icon.substring('data:image/svg+xml;base64,'.length));
let xml = '';
try {
xml = Buffer.from(icon.substring('data:image/svg+xml;base64,'.length), 'base64').toString();
} catch {
// Do nothing
}
image = (
<SvgXml
xml={xml}