chore: feat: save ThreadMessagesView filter preferences on mmkv (#5653)

* chore: update currentFilter value in ThreadMessagesView

* feat: save ThreadMessagesView filter preferences on mmkv
This commit is contained in:
Gleidson Daniel Silva 2024-04-18 08:51:53 -03:00 committed by GitHub
parent d19239d290
commit 0429cd421b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 8 deletions

View File

@ -35,8 +35,10 @@ import styles from './styles';
import { IApplicationState, IBaseScreen, IMessage, SubscriptionType, TSubscriptionModel, TThreadModel } from '../../definitions';
import { getUidDirectMessage, debounce, isIOS } from '../../lib/methods/helpers';
import { Services } from '../../lib/services';
import UserPreferences from '../../lib/methods/userPreferences';
const API_FETCH_COUNT = 50;
const THREADS_FILTER = 'threadsFilter';
interface IThreadMessagesViewState {
loading: boolean;
@ -216,8 +218,18 @@ class ThreadMessagesView extends React.Component<IThreadMessagesViewProps, IThre
}
};
init = () => {
initFilter = () =>
new Promise<void>(resolve => {
const savedFilter = UserPreferences.getString(THREADS_FILTER);
if (savedFilter) {
this.setState({ currentFilter: savedFilter as Filter }, () => resolve());
}
resolve();
});
init = async () => {
const { subscription } = this.state;
await this.initFilter();
if (!subscription) {
return this.load();
}
@ -414,13 +426,6 @@ class ThreadMessagesView extends React.Component<IThreadMessagesViewProps, IThre
return messages;
};
// method to update state with filtered threads
filterThreads = () => {
const { messages, subscription } = this.state;
const displayingThreads = this.getFilteredThreads(messages, subscription);
this.setState({ displayingThreads });
};
showFilterDropdown = () => this.setState({ showFilterDropdown: true });
closeFilterDropdown = () => this.setState({ showFilterDropdown: false });
@ -429,6 +434,7 @@ class ThreadMessagesView extends React.Component<IThreadMessagesViewProps, IThre
const { messages, subscription } = this.state;
const displayingThreads = this.getFilteredThreads(messages, subscription, filter);
this.setState({ currentFilter: filter, displayingThreads, showFilterDropdown: false });
UserPreferences.setString(THREADS_FILTER, filter);
};
toggleFollowThread = async (isFollowingThread: boolean, tmid: string) => {