Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop showing donation alert for pro users #2542

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,16 @@
>
Donate
</button>
@if ((account$ | async)?.plan?.canUpgradePro) {
or
<button
class="btn alert-action"
(click)="setShowUpgradeDialog(true)"
track-id="upgrade_pro"
>
Upgrade to Pro
</button>
}
</ng-template>
</nz-layout>
</nz-layout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { DbService } from './db.service';
import { uaSeedHash } from '../utils/simple_hash';
import { switchMap, map } from 'rxjs/operators';
import { AltairConfig } from 'altair-graphql-core/build/config';
import { AccountService } from './account/account.service';
import { fromPromise } from '../utils';

@Injectable()
export class DonationService {
Expand All @@ -15,6 +17,7 @@ export class DonationService {

constructor(
private dbService: DbService,
private accountService: AccountService,
private altairConfig: AltairConfig
) {}

Expand Down Expand Up @@ -45,9 +48,15 @@ export class DonationService {
const actionCount$ = this.dbService.getItem(this.actionCountKey);
const seed$ = this.dbService.getItem(this.seedKey);
const curHash$ = this.dbService.getItem(this.hashKey);
const userPlan$ = fromPromise(this.accountService.getPlan());

return zip(actionCount$, seed$, curHash$).pipe(
map(([actionCount, seed, curHash]) => {
return zip(actionCount$, seed$, curHash$, userPlan$).pipe(
map(([actionCount, seed, curHash, userPlan]) => {
if (userPlan.id === 'pro') {
// Reset count
this.dbService.setItem(this.actionCountKey, 0);
return false;
}
if (
actionCount &&
actionCount >= this.altairConfig.donation.action_count_threshold
Expand Down
30 changes: 17 additions & 13 deletions packages/altair-docs/.vitepress/plugins/github-metadata.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ import path from 'path';
import { Octokit } from '@octokit/rest';
import NodeCache from 'node-cache';
// Does the cache persist over several runs? 🤔
const myCache = new NodeCache( { stdTTL: 600 } );
const myCache = new NodeCache({ stdTTL: 600 });

const getGithubMetadata = async ({ owner = '', repo = '' }) => {

let githubToken = '';
try {
githubToken = fs.readFileSync(path.resolve(__dirname, './github-token'), 'utf-8');
} catch (error) {
githubToken = fs.readFileSync(
path.resolve(__dirname, './github-token'),
'utf-8'
);
} catch (error) {}
githubToken ||= process.env.GITHUB_TOKEN ?? '';

if (!githubToken) {
console.log('no github token found');
}
githubToken ||= process.env.GITHUB_TOKEN ?? '';

const octokit = new Octokit({
auth: githubToken || undefined,
Expand All @@ -25,10 +29,10 @@ const getGithubMetadata = async ({ owner = '', repo = '' }) => {

const resolvers = {
latest_release: async () => {
const fromCache = myCache.get('latest_release');
if (fromCache) {
return fromCache;
}
// const fromCache = myCache.get('latest_release');
// if (fromCache) {
// return fromCache;
// }
const { data } = await octokit.rest.repos.getLatestRelease({ owner, repo });
if (data) {
myCache.set('latest_release', data);
Expand All @@ -48,9 +52,9 @@ const getGithubMetadata = async ({ owner = '', repo = '' }) => {
// return data;
// },
releases_url: async () => `${repoUrl}/releases`,
}
};
const keys = Object.keys(resolvers);
const vls = await Promise.allSettled(keys.map(_ => resolvers[_]()));
const vls = await Promise.allSettled(keys.map((_) => resolvers[_]()));

return vls.reduce((acc, cur, i) => {
if (cur.status === 'rejected') {
Expand All @@ -60,12 +64,12 @@ const getGithubMetadata = async ({ owner = '', repo = '' }) => {
return {
...acc,
[keys[i]]: cur.value,
}
};
}, {});
};

declare const data: any;
export { data }
export { data };

export default {
async load() {
Expand Down
5 changes: 4 additions & 1 deletion packages/altair-docs/updated.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ import { data } from './.vitepress/plugins/github-metadata.data'

# Altair has been updated! - {{ data?.latest_release?.tag_name }}

<Markdown :markdown="data?.latest_release?.body" />
<Markdown
v-if="data?.latest_release?.body"
:markdown="data?.latest_release?.body"
/>
Loading