feat(core): simplify subscribe page param (#8518)

AF-1481
This commit is contained in:
forehalo
2024-10-17 07:05:00 +00:00
parent b7fac5acb8
commit 7dae5c5dd5
4 changed files with 116 additions and 70 deletions

View File

@@ -1,4 +1,5 @@
import { type CreateCheckoutSessionInput } from '@affine/graphql';
import { mixpanel } from '@affine/track';
import { OnEvent, Service } from '@toeverything/infra';
import { Subscription } from '../entities/subscription';
@@ -13,6 +14,22 @@ export class SubscriptionService extends Service {
constructor(private readonly store: SubscriptionStore) {
super();
this.subscription.ai$
.map(sub => !!sub)
.distinctUntilChanged()
.subscribe(ai => {
mixpanel.people.set({
ai,
});
});
this.subscription.pro$
.map(sub => !!sub)
.distinctUntilChanged()
.subscribe(pro => {
mixpanel.people.set({
pro,
});
});
}
async createCheckoutSession(input: CreateCheckoutSessionInput) {

View File

@@ -1,21 +1,22 @@
import type { QuotaQuery } from '@affine/graphql';
import { createEvent, OnEvent, Service } from '@toeverything/infra';
import { mixpanel } from '@affine/track';
import { OnEvent, Service } from '@toeverything/infra';
import { UserQuota } from '../entities/user-quota';
import { AccountChanged } from './auth';
type UserQuotaInfo = NonNullable<QuotaQuery['currentUser']>['quota'];
export const UserQuotaChanged = createEvent<UserQuotaInfo>('UserQuotaChanged');
@OnEvent(AccountChanged, e => e.onAccountChanged)
export class UserQuotaService extends Service {
constructor() {
super();
this.quota.quota$.distinctUntilChanged().subscribe(q => {
this.eventBus.emit(UserQuotaChanged, q);
});
this.quota.quota$
.map(q => q?.humanReadable.name)
.distinctUntilChanged()
.subscribe(quota => {
mixpanel.people.set({
quota,
});
});
}
quota = this.framework.createEntity(UserQuota);