mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-05 21:29:11 +00:00
Clean up some of the suggestions code, improve randomness of cards'
This commit is contained in:
@@ -32,6 +32,14 @@ interface ChatBodyDataProps {
|
||||
isLoadingUserConfig: boolean;
|
||||
}
|
||||
|
||||
function FisherYatesShuffle(array: any[]) {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
function ChatBodyData(props: ChatBodyDataProps) {
|
||||
const [message, setMessage] = useState("");
|
||||
const [processingMessage, setProcessingMessage] = useState(false);
|
||||
@@ -54,7 +62,7 @@ function ChatBodyData(props: ChatBodyDataProps) {
|
||||
});
|
||||
|
||||
function shuffleAndSetOptions() {
|
||||
const shuffled = [...suggestionsData].sort(() => 0.5 - Math.random());
|
||||
const shuffled = FisherYatesShuffle(suggestionsData);
|
||||
setShuffledOptions(shuffled.slice(0, 3));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user