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

Commit 30d6fcd

Browse files
feat: remove collection deploy and use deck
1 parent 094dffb commit 30d6fcd

File tree

9 files changed

+81
-152
lines changed

9 files changed

+81
-152
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import deckStore from '../../../../stores/deck.store';
44
import userStore from '../../../../stores/user.store';
55
import shareStore from '../../../../stores/share.store';
66
import authStore from '../../../../stores/auth.store';
7-
import deployStore from '../../../../stores/deploy.store';
87

98
@Component({
109
tag: 'app-publish-done',
@@ -59,7 +58,7 @@ export class AppPublishDone {
5958
return undefined;
6059
}
6160

62-
if (!deployStore.state.deploy || !deployStore.state.deploy.data) {
61+
if (!deckStore.state.deck.data.github) {
6362
return (
6463
<ion-label class="published-url ion-padding ion-text-center">
6564
The source code of the presentation is processing <ion-spinner color="tertiary"></ion-spinner>
@@ -70,7 +69,7 @@ export class AppPublishDone {
7069
return (
7170
<ion-label class="published-url ion-padding ion-text-center">
7271
The source code of the presentation has been submitted to a{' '}
73-
<a href={`${deployStore.state.deploy.data.github.repo.url}/pulls`} target="_blank" rel="noopener noreferrer">
72+
<a href={`${deckStore.state.deck.data.github.repo.url}/pulls`} target="_blank" rel="noopener noreferrer">
7473
repository
7574
</a>{' '}
7675
on GitHub <ion-icon name="logo-github" aria-label="GitHub"></ion-icon>.

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ import errorStore from '../../../../stores/error.store';
77
import feedStore from '../../../../stores/feed.store';
88
import apiUserStore from '../../../../stores/api.user.store';
99
import authStore from '../../../../stores/auth.store';
10-
import deployStore from '../../../../stores/deploy.store';
1110

1211
import {Deck} from '../../../../models/data/deck';
13-
import {Deploy} from '../../../../models/data/deploy';
1412

1513
import {Resources} from '../../../../utils/core/resources';
1614

@@ -63,7 +61,7 @@ export class AppPublishEdit {
6361

6462
private publishService: PublishService;
6563

66-
private destroyDeployListener;
64+
private destroyDeckListener;
6765

6866
constructor() {
6967
this.deckService = DeckService.getInstance();
@@ -78,12 +76,11 @@ export class AppPublishEdit {
7876
async componentWillLoad() {
7977
await this.init();
8078

81-
this.destroyDeployListener = deployStore.onChange('deploy', async (_deploy: Deploy | undefined) => {
79+
this.destroyDeckListener = deckStore.onChange('deck', async (deck: Deck | undefined) => {
80+
// Deck is maybe updating while we have set it to true manually
8281
this.publishing =
83-
deployStore.state.deploy &&
84-
deployStore.state.deploy.data &&
85-
deployStore.state.deploy.data.api &&
86-
(deployStore.state.deploy.data.api.status === 'scheduled' || deployStore.state.deploy.data.api.status === 'failure');
82+
this.publishing ||
83+
(deck.data.deploy && deck.data.deploy.api && (deck.data.deploy.api.status === 'scheduled' || deck.data.deploy.api.status === 'failure'));
8784
});
8885
}
8986

@@ -92,8 +89,8 @@ export class AppPublishEdit {
9289
}
9390

9491
disconnectedCallback() {
95-
if (this.destroyDeployListener) {
96-
this.destroyDeployListener();
92+
if (this.destroyDeckListener) {
93+
this.destroyDeckListener();
9794
}
9895
}
9996

@@ -190,29 +187,25 @@ export class AppPublishEdit {
190187
}
191188

192189
private onSuccessfulPublish() {
193-
const destroyDeploySuccessfulListener = deployStore.onChange('deploy', async (deploy: Deploy | undefined) => {
194-
if (deploy && deploy.data && deploy.data.api && deploy.data.api.status === 'successful') {
195-
destroyDeploySuccessfulListener();
190+
const currentDeck: Deck = {...deckStore.state.deck};
191+
192+
const destroyDeckDeployListener = deckStore.onChange('deck', async (deck: Deck | undefined) => {
193+
if (deck && deck.data && deck.data.deploy && deck.data.deploy.api && deck.data.deploy.api.status === 'successful') {
194+
destroyDeckDeployListener();
196195

197-
await this.delayRefreshDeck();
196+
// In case the user would have browse the feed before, reset it to fetch is updated or new presentation
197+
feedStore.reset();
198+
199+
await this.delayNavigation(currentDeck.data.api_id !== deckStore.state.deck.data.api_id);
198200
}
199201
});
200202
}
201203

202204
// Even if we fixed the delay to publish to Cloudfare CDN (#195), sometimes if too quick, the presentation will not be correctly published
203205
// Therefore, to avoid such problem, we add a bit of delay in the process but only for the first publish
204-
private async delayRefreshDeck() {
206+
private async delayNavigation(newApiId: boolean) {
205207
this.progress = 0;
206208

207-
const currentDeck: Deck = {...deckStore.state.deck};
208-
209-
await this.publishService.refreshDeck(currentDeck.id);
210-
211-
// In case the user would have browse the feed before, reset it to fetch is updated or new presentation
212-
feedStore.reset();
213-
214-
const newApiId: boolean = currentDeck.data.api_id !== deckStore.state.deck.data.api_id;
215-
216209
const interval = setInterval(
217210
() => {
218211
this.progress += 0.1;
@@ -522,7 +515,7 @@ export class AppPublishEdit {
522515
}
523516

524517
private renderGitHubText() {
525-
if (!deployStore.state.deploy || !deployStore.state.deploy.data) {
518+
if (!deckStore.state.deck || !deckStore.state.deck.data || !deckStore.state.deck.data.github) {
526519
return <p class="meta-text">Push the source code of the presentation to a new public repository of your GitHub account?</p>;
527520
}
528521

studio/src/app/modals/editor/app-publish/app-publish.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Component, Element, Listen, h, State} from '@stencil/core';
22

3-
import {DeployService} from '../../../services/data/deploy/deploy.service';
3+
import {PublishService} from '../../../services/editor/publish/publish.service';
44

55
@Component({
66
tag: 'app-publish',
@@ -12,16 +12,16 @@ export class AppPublish {
1212
@State()
1313
private publishedUrl: string;
1414

15-
private deployService: DeployService;
15+
private publishService: PublishService;
1616

1717
private unsubscribeSnapshot: () => void | undefined;
1818

1919
constructor() {
20-
this.deployService = DeployService.getInstance();
20+
this.publishService = PublishService.getInstance();
2121
}
2222

2323
async componentWillLoad() {
24-
this.unsubscribeSnapshot = await this.deployService.snapshot();
24+
this.unsubscribeSnapshot = await this.publishService.snapshot();
2525
}
2626

2727
async componentDidLoad() {

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
import {UserSocial} from './user';
22

3+
export interface DeckDeployData {
4+
status: 'scheduled' | 'failure' | 'successful';
5+
updated_at: firebase.firestore.Timestamp;
6+
}
7+
8+
export interface DeckDeploy {
9+
github?: DeckDeployData;
10+
api?: DeckDeployData;
11+
}
12+
13+
export interface DeckGitHubRepo {
14+
id: string;
15+
url: string;
16+
name: string;
17+
nameWithOwner: string;
18+
}
19+
20+
export interface DeckGitHub {
21+
repo: DeckGitHubRepo;
22+
}
23+
324
export interface DeckMetaAuthor {
425
name: string;
526
photo_url?: string;
@@ -51,6 +72,10 @@ export interface DeckData {
5172

5273
meta?: DeckMeta;
5374

75+
deploy?: DeckDeploy;
76+
77+
github?: DeckGitHub;
78+
5479
clone?: DeckClone;
5580

5681
created_at?: firebase.firestore.Timestamp;

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

Lines changed: 0 additions & 30 deletions
This file was deleted.

studio/src/app/services/data/deploy/deploy.service.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

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

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import 'firebase/auth';
44

55
import deckStore from '../../../stores/deck.store';
66
import userStore from '../../../stores/user.store';
7+
import errorStore from '../../../stores/error.store';
78

8-
import {Deck, DeckMetaAuthor} from '../../../models/data/deck';
9+
import {Deck, DeckData, DeckMetaAuthor} from '../../../models/data/deck';
910

1011
import {UserSocial} from '../../../models/data/user';
1112

@@ -83,20 +84,6 @@ export class PublishService {
8384
});
8485
}
8586

86-
// Otherwise we gonna kept in memory references like firebase.firestore.FieldValue.delete instead of null values
87-
refreshDeck(deckId: string): Promise<void> {
88-
return new Promise<void>(async (resolve, reject) => {
89-
try {
90-
const freshDeck: Deck = await this.deckService.get(deckId);
91-
deckStore.state.deck = {...freshDeck};
92-
93-
resolve();
94-
} catch (err) {
95-
reject(err);
96-
}
97-
});
98-
}
99-
10087
private updateDeckMeta(description: string, tags: string[], github: boolean): Promise<void> {
10188
return new Promise<void>(async (resolve, reject) => {
10289
try {
@@ -171,4 +158,33 @@ export class PublishService {
171158
}
172159
});
173160
}
161+
162+
snapshot(): Promise<() => void | undefined> {
163+
return new Promise<() => void | undefined>((resolve) => {
164+
const deck: Deck = deckStore.state.deck;
165+
166+
if (!deck || !deck.id) {
167+
resolve(undefined);
168+
return;
169+
}
170+
171+
const firestore: firebase.firestore.Firestore = firebase.firestore();
172+
const unsubscribe = firestore
173+
.collection(`decks`)
174+
.doc(deck.id)
175+
.onSnapshot(
176+
(deploySnapshot: firebase.firestore.DocumentSnapshot<DeckData>) => {
177+
deckStore.state.deck = {
178+
id: deploySnapshot.id,
179+
data: deploySnapshot.data(),
180+
};
181+
},
182+
(_err) => {
183+
errorStore.state.error = 'Cannont retrieve the deck information.';
184+
}
185+
);
186+
187+
resolve(unsubscribe);
188+
});
189+
}
174190
}

studio/src/app/stores/deck.store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ onChange('deck', (deck: Deck | null) => {
1919
state.published = deck && deck.data && deck.data.meta && deck.data.meta.published ? deck.data.meta.published : false;
2020
});
2121

22-
export default {state, reset};
22+
export default {state, onChange, reset};

studio/src/app/stores/deploy.store.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)