mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
updates for suggestions
This commit is contained in:
parent
a22b1cb9f5
commit
975b77e728
@ -453,7 +453,23 @@ const ChangeConnectionBlockModal = React.memo(
|
||||
const connection = blockData?.meta?.connection;
|
||||
const connStatusAtom = getConnStatusAtom(connection);
|
||||
const connStatus = jotai.useAtomValue(connStatusAtom);
|
||||
const [suggestions, setSuggestions] = React.useState<SuggestionsType[]>([]);
|
||||
const [connList, setConnList] = React.useState<Array<string>>([]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!changeConnModalOpen) {
|
||||
setConnList([]);
|
||||
return;
|
||||
}
|
||||
const prtn = WshServer.ConnListCommand({ timeout: 2000 });
|
||||
prtn.then((connList) => {
|
||||
setConnList(connList ?? []);
|
||||
}).catch((e) => console.log("unable to load conn list from backend. using blank list: ", e));
|
||||
}, [changeConnModalOpen]);
|
||||
|
||||
React.useEffect(() => {
|
||||
console.log("connSelected is: ", connSelected);
|
||||
}, [connSelected]);
|
||||
|
||||
const changeConnection = React.useCallback(
|
||||
async (connName: string) => {
|
||||
if (connName == "") {
|
||||
@ -482,21 +498,15 @@ const ChangeConnectionBlockModal = React.memo(
|
||||
},
|
||||
[blockId, blockData]
|
||||
);
|
||||
React.useEffect(() => {
|
||||
const loadFromBackend = async () => {
|
||||
let connList: Array<string>;
|
||||
|
||||
try {
|
||||
connList = await WshServer.ConnListCommand({ timeout: 2000 });
|
||||
} catch (e) {
|
||||
console.log("unable to load conn list from backend. using blank list: ", e);
|
||||
}
|
||||
if (!connList) {
|
||||
connList = [];
|
||||
}
|
||||
let createNew: boolean = true;
|
||||
let showLocal: boolean = true;
|
||||
let showReconnect: boolean = true;
|
||||
if (connSelected == "") {
|
||||
createNew = false;
|
||||
} else {
|
||||
showLocal = false;
|
||||
showReconnect = false;
|
||||
}
|
||||
const filteredList: Array<string> = [];
|
||||
for (const conn of connList) {
|
||||
@ -536,7 +546,7 @@ const ChangeConnectionBlockModal = React.memo(
|
||||
console.log("added to priority items");
|
||||
priorityItems.push(newConnectionSuggestion);
|
||||
}
|
||||
if (connStatus.status == "disconnected" || connStatus.status == "error") {
|
||||
if (showReconnect && (connStatus.status == "disconnected" || connStatus.status == "error")) {
|
||||
priorityItems.push(reconnectSuggestion);
|
||||
}
|
||||
const prioritySuggestions: SuggestionConnectionScope = {
|
||||
@ -546,8 +556,10 @@ const ChangeConnectionBlockModal = React.memo(
|
||||
const localName = getUserName() + "@" + getHostName();
|
||||
const localSuggestion: SuggestionConnectionScope = {
|
||||
headerText: "Local",
|
||||
items: [
|
||||
{
|
||||
items: [],
|
||||
};
|
||||
if (showLocal) {
|
||||
localSuggestion.items.push({
|
||||
status: "connected",
|
||||
icon: "laptop",
|
||||
iconColor: "var(--grey-text-color)",
|
||||
@ -558,9 +570,8 @@ const ChangeConnectionBlockModal = React.memo(
|
||||
changeConnection("");
|
||||
globalStore.set(changeConnModalAtom, false);
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
});
|
||||
}
|
||||
const remoteItems = filteredList.map((connName) => {
|
||||
const item: SuggestionConnectionItem = {
|
||||
status: "connected",
|
||||
@ -576,20 +587,17 @@ const ChangeConnectionBlockModal = React.memo(
|
||||
items: remoteItems,
|
||||
};
|
||||
|
||||
let out: Array<SuggestionsType> = [];
|
||||
let suggestions: Array<SuggestionsType> = [];
|
||||
if (prioritySuggestions.items.length > 0) {
|
||||
out.push(prioritySuggestions);
|
||||
suggestions.push(prioritySuggestions);
|
||||
}
|
||||
if (localSuggestion.items.length > 0) {
|
||||
out.push(localSuggestion);
|
||||
suggestions.push(localSuggestion);
|
||||
}
|
||||
if (remoteSuggestions.items.length > 0) {
|
||||
out.push(remoteSuggestions);
|
||||
suggestions.push(remoteSuggestions);
|
||||
}
|
||||
setSuggestions(out);
|
||||
};
|
||||
loadFromBackend();
|
||||
}, [connStatus, setSuggestions, connSelected, changeConnection]);
|
||||
|
||||
const handleTypeAheadKeyDown = React.useCallback(
|
||||
(waveEvent: WaveKeyboardEvent): boolean => {
|
||||
if (keyutil.checkKeyPressed(waveEvent, "Enter")) {
|
||||
@ -607,9 +615,7 @@ const ChangeConnectionBlockModal = React.memo(
|
||||
},
|
||||
[changeConnModalAtom, viewModel, blockId, connSelected]
|
||||
);
|
||||
React.useEffect(() => {
|
||||
console.log("connSelected is: ", connSelected);
|
||||
}, [connSelected]);
|
||||
|
||||
if (!changeConnModalOpen) {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user