mattermost-mobile/app/components/drafts_buttton/index.ts
2025-04-14 22:08:59 +05:30

31 lines
1.2 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {withDatabase, withObservables} from '@nozbe/watermelondb/react';
import {of as of$} from 'rxjs';
import {switchMap, distinctUntilChanged} from 'rxjs/operators';
import {Screens} from '@constants';
import {observeCurrentTeamId} from '@queries/servers/system';
import {observeTeamLastChannelId} from '@queries/servers/team';
import DraftsButton from './drafts_button';
import type {WithDatabaseArgs} from '@typings/database/database';
const enhanced = withObservables(['shouldHighlightActive'], ({database, shouldHighlightActive}: {shouldHighlightActive: boolean} & WithDatabaseArgs) => {
const currentTeamId = observeCurrentTeamId(database);
const isActiveTab = currentTeamId.pipe(
switchMap(
(teamId) => observeTeamLastChannelId(database, teamId),
),
switchMap((lastChannelId) => of$(lastChannelId === Screens.GLOBAL_DRAFTS || (shouldHighlightActive && !lastChannelId))),
distinctUntilChanged(),
);
return {
isActiveTab,
};
});
export default withDatabase(enhanced(DraftsButton));