Skip to content

Commit

Permalink
1) Now initial filter is empty and not undefined, a number of fails i…
Browse files Browse the repository at this point in the history
…s resolved

2) Just created entries are added to cache of very first page and not to cache of current page, this made no sense
3) Just created entries are not showed if current filter does not require this
  • Loading branch information
vmonakhov committed Jan 12, 2025
1 parent 2b16289 commit ec0813a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/components/PerspectiveView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,17 @@ class P extends React.Component {
}

componentDidUpdate(prevProps) {
const { data } = this.props;
const { data, createdEntries, page, filter } = this.props;
if (!data.perspective) {
return;
}
if (data !== prevProps.data) {
this.setState({ entriesTotal: !data.error ? data.perspective.perspective_page.entries_total : 0 });
}
// We clear createdEntries if page was switched, no filter was used and it was not changed
if (createdEntries.length && page !== prevProps.page && !filter && filter === prevProps.filter) {
this.props.resetAddedLexes();
}
}

reRender() {
Expand Down Expand Up @@ -416,14 +420,18 @@ class P extends React.Component {
create_lexicalentry: { lexicalentry }
} = d;

/*
/* We'll update cache for very first page to move createdEntries there after page switching
*/

cache.updateQuery(
{
query: queryLexicalEntries,
variables: query_args
variables: {...query_args, offset: 0, createdEntries: []}
},

(data) => {
if (!loading && !error) {
if (!loading && !error && data) {
const result = cloneDeep(data);
result.perspective.perspective_page.lexical_entries.unshift(lexicalentry);
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Perspective/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ const Tools = ({
};

const handlers = compose(
withState("value", "updateValue", props => props.filter.value),
withState("value", "updateValue", props => props.filter.value ?? ""),
withState("isCaseSens", "setCaseSens", true),
withState("isRegexp", "setRegexp", false),
withHandlers({
Expand Down

0 comments on commit ec0813a

Please sign in to comment.