Skip to content

Commit

Permalink
Fix: Autocollapsing of history items (#2331)
Browse files Browse the repository at this point in the history
  • Loading branch information
Onokaev authored Jan 12, 2023
1 parent 121872e commit f42316f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/app/views/sidebar/history/History.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import {
Announced,
ContextualMenuItemType, DefaultButton, DetailsList, DetailsRow, Dialog,
DialogFooter, DialogType, getId, getTheme, IColumn, IconButton,
IGroup,
Label, MessageBar, MessageBarType, PrimaryButton, SearchBox, SelectionMode, styled, TooltipHost
} from '@fluentui/react';
import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { FormattedMessage, injectIntl } from 'react-intl';
import { useDispatch } from 'react-redux';

Expand Down Expand Up @@ -91,6 +92,21 @@ const History = (props: any) => {
const [historyItems, setHistoryItems] = useState<IHistoryItem[]>(history);
const [hideDialog, setHideDialog] = useState(true);
const [category, setCategory] = useState('');
const [groups, setGroups] = useState<IGroup[]>([]);
const [searchStarted, setSearchStarted] = useState(false);

const shouldGenerateGroups = useRef(true);

const items = getItems(historyItems);

useEffect(() => {
if (shouldGenerateGroups.current) {
setGroups(generateGroupsFromList(items, 'category'));
if (groups && groups.length > 0) {
shouldGenerateGroups.current = false;
}
}
}, [historyItems, searchStarted])

const classes = classNames(props);

Expand All @@ -103,6 +119,8 @@ const History = (props: any) => {
}

const searchValueChanged = (_event: any, value?: string): void => {
shouldGenerateGroups.current = true;
setSearchStarted(searchStatus => !searchStatus);
let content = [...history];
if (value) {
const keyword = value.toLowerCase();
Expand Down Expand Up @@ -453,8 +471,6 @@ const History = (props: any) => {
});
}

const items = getItems(historyItems);
const groups = generateGroupsFromList(items, 'category');

return (
<>
Expand Down

0 comments on commit f42316f

Please sign in to comment.