mattermost-mobile/app/components/drafts_buttton/index.ts
Rajat Dabade 6bdcf2be49
Remaining test for draft and Scheduled post (#8887)
* Added test for draft_scheduled_post and header component

* Added test for drafts_button/index.ts

* Added test for send_button/index.ts

* Added test for servers/scheduled_post.ts queries

* Added test for global_scheduled_post_list/index.ts

* Added test for rescheduled draft index file and minor update

* Added test for core option and index

* Added test for scheduled post options

* Added test for send_draft index file

* updated test for draft_scheduled_post and draft_scheduled_post_header

* Updated test for drafts_button index

* Updated test for send_button index

* Updated test for server/scheduled_post

* Updated test for global_scheduled_post/index

* removed the unnecessary config and team data to populate in db for test

* Update app/components/draft_scheduled_post/draft_scheduled_post.test.tsx

Co-authored-by: Daniel Espino García <larkox@gmail.com>

* linter fixes

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Daniel Espino García <larkox@gmail.com>
2025-07-01 13:47:02 +05:30

35 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';
type Props = WithDatabaseArgs & {
shouldHighlightActive: boolean;
}
const enhanced = withObservables(['shouldHighlightActive'], ({database, shouldHighlightActive}: Props) => {
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));