Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit b31aaf1

Browse files
refactor: github publish information
1 parent 30d6fcd commit b31aaf1

File tree

7 files changed

+23
-13
lines changed

7 files changed

+23
-13
lines changed

cloud/functions/src/model/data/deck.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export interface DeckGitHubRepo {
2020
}
2121

2222
export interface DeckGitHub {
23-
repo: DeckGitHubRepo;
23+
repo?: DeckGitHubRepo;
24+
publish: boolean;
2425
}
2526

2627
export interface DeckMetaAuthor {
@@ -43,7 +44,6 @@ export interface DeckMeta {
4344
published_at: firestore.Timestamp;
4445

4546
feed: boolean;
46-
github?: boolean;
4747

4848
updated_at: firestore.Timestamp;
4949
}

cloud/functions/src/watch/publish/github/utils/github-db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as admin from 'firebase-admin';
22

33
import {Token, TokenData} from '../../../../model/data/token';
4-
import {DeckData, DeckGitHubRepo} from '../../../../model/data/deck';
4+
import {DeckData, DeckGitHub, DeckGitHubRepo} from '../../../../model/data/deck';
55

66
export function findToken(userId: string): Promise<Token> {
77
return new Promise<Token>(async (resolve, reject) => {
@@ -43,7 +43,7 @@ export function updateDeckGitHub(deckId: string, repo: DeckGitHubRepo | undefine
4343
updated_at: admin.firestore.Timestamp.now(),
4444
github: {
4545
repo: {...repo},
46-
},
46+
} as DeckGitHub,
4747
};
4848

4949
const documentReference: admin.firestore.DocumentReference = admin.firestore().doc(`/decks/${deckId}`);

cloud/functions/src/watch/publish/github/utils/github-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function getRepo(githubToken: string, user: GitHubUser, userId: str
1515
const project: string = deckData.meta.title.replace(' ', '-').toLowerCase();
1616
const description: string = deckData.meta.description ? (deckData.meta.description as string) : '';
1717

18-
if (deckData.github) {
18+
if (deckData.github && deckData.github.repo) {
1919
const existingRepo: DeckGitHubRepo | undefined = await findRepo(githubToken, user, deckData.github.repo.name);
2020

2121
if (existingRepo) {

studio/src/app/components/editor/publish/app-publish-done/app-publish-done.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ export class AppPublishDone {
5454
return undefined;
5555
}
5656

57-
if (!deckStore.state.deck || !deckStore.state.deck.data || !deckStore.state.deck.data.meta || !deckStore.state.deck.data.meta.github) {
57+
if (!deckStore.state.deck || !deckStore.state.deck.data || !deckStore.state.deck.data.github || !deckStore.state.deck.data.github.publish) {
5858
return undefined;
5959
}
6060

61-
if (!deckStore.state.deck.data.github) {
61+
if (!deckStore.state.deck.data.github || !deckStore.state.deck.data.github.repo) {
6262
return (
6363
<ion-label class="published-url ion-padding ion-text-center">
6464
The source code of the presentation is processing <ion-spinner color="tertiary"></ion-spinner>

studio/src/app/components/editor/publish/app-publish-edit/app-publish-edit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class AppPublishEdit {
105105
? (deckStore.state.deck.data.meta.description as string)
106106
: await this.getFirstSlideContent();
107107
this.tags = deckStore.state.deck.data.meta && deckStore.state.deck.data.meta.tags ? (deckStore.state.deck.data.meta.tags as string[]) : [];
108-
this.pushToGitHub = deckStore.state.deck.data.meta && deckStore.state.deck.data.meta.github !== undefined ? deckStore.state.deck.data.meta.github : true;
108+
this.pushToGitHub = deckStore.state.deck.data.github ? deckStore.state.deck.data.github.publish : true;
109109
}
110110

111111
private getFirstSlideContent(): Promise<string> {

studio/src/app/models/data/deck.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export interface DeckGitHubRepo {
1818
}
1919

2020
export interface DeckGitHub {
21-
repo: DeckGitHubRepo;
21+
repo?: DeckGitHubRepo;
22+
publish: boolean;
2223
}
2324

2425
export interface DeckMetaAuthor {
@@ -41,7 +42,6 @@ export interface DeckMeta {
4142
published_at?: firebase.firestore.Timestamp;
4243

4344
feed?: boolean;
44-
github?: boolean;
4545

4646
updated_at: firebase.firestore.Timestamp;
4747
}

studio/src/app/services/editor/publish/publish.service.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'firebase/auth';
55
import deckStore from '../../../stores/deck.store';
66
import userStore from '../../../stores/user.store';
77
import errorStore from '../../../stores/error.store';
8+
import authStore from '../../../stores/auth.store';
89

910
import {Deck, DeckData, DeckMetaAuthor} from '../../../models/data/deck';
1011

@@ -68,7 +69,7 @@ export class PublishService {
6869
deckId: deck.id,
6970
ownerId: deck.data.owner_id,
7071
publish: true,
71-
github: deck.data.meta.github,
72+
github: deck.data.github ? deck.data.github.publish : false,
7273
}),
7374
});
7475

@@ -99,13 +100,11 @@ export class PublishService {
99100
if (!deck.data.meta) {
100101
deck.data.meta = {
101102
title: deck.data.name,
102-
github: github,
103103
updated_at: now,
104104
};
105105
} else {
106106
deck.data.meta.title = deck.data.name;
107107
deck.data.meta.updated_at = now;
108-
deck.data.meta.github = github;
109108
}
110109

111110
if (description && description !== undefined && description !== '') {
@@ -149,6 +148,17 @@ export class PublishService {
149148
deck.data.meta.author = firebase.firestore.FieldValue.delete();
150149
}
151150

151+
// Update GitHub info (push or not) for GitHub users so next time user publish, the choice is kept
152+
if (authStore.state.gitHub) {
153+
if (deck.data.github) {
154+
deck.data.github.publish = github;
155+
} else {
156+
deck.data.github = {
157+
publish: github,
158+
};
159+
}
160+
}
161+
152162
const updatedDeck: Deck = await this.deckService.update(deckStore.state.deck);
153163
deckStore.state.deck = {...updatedDeck};
154164

0 commit comments

Comments
 (0)