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

Commit 483a240

Browse files
refactor: extract action to component
1 parent bcf413b commit 483a240

File tree

4 files changed

+94
-54
lines changed

4 files changed

+94
-54
lines changed

studio/src/app/components/editor/app-add-slide-action/app-add-slide-action.scss

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {Component, Event, EventEmitter} from '@stencil/core';
2+
3+
@Component({
4+
tag: 'app-add-slide-action',
5+
styleUrl: 'app-add-slide-action.scss',
6+
shadow: false
7+
})
8+
export class AppAddSlideAction {
9+
10+
@Event() private actionOpenSlideAdd: EventEmitter<UIEvent>;
11+
12+
private openSlideAdd($event: UIEvent) {
13+
this.actionOpenSlideAdd.emit($event);
14+
}
15+
16+
render() {
17+
return <ion-button onClick={(e: UIEvent) => this.openSlideAdd(e)} color="primary" shape="round"
18+
size="small">
19+
<ion-label>Add slide</ion-label>
20+
</ion-button>;
21+
}
22+
23+
}

studio/src/app/pages/app-editor/app-editor.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,15 @@ export class AppEditor {
177177
});
178178
}
179179

180-
private async openSlideAdd($event: UIEvent) {
180+
@Listen('actionOpenSlideAdd')
181+
async onActionOpenSlideAdd($event: CustomEvent) {
182+
if (!$event || !$event.detail) {
183+
return;
184+
}
185+
181186
const popover: HTMLIonPopoverElement = await this.popoverController.create({
182187
component: 'app-slide-type',
183-
event: $event,
188+
event: $event.detail,
184189
mode: 'ios',
185190
cssClass: 'app-slide-type'
186191
});
@@ -349,10 +354,7 @@ export class AppEditor {
349354
</ion-buttons>
350355

351356
<ion-buttons slot="end">
352-
<ion-button onClick={(e: UIEvent) => this.openSlideAdd(e)} color="primary" shape="round"
353-
size="small">
354-
<ion-label>Add slide</ion-label>
355-
</ion-button>
357+
<app-add-slide-action></app-add-slide-action>
356358
</ion-buttons>
357359
</ion-toolbar>
358360
</ion-footer>,

studio/src/components.d.ts

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,6 @@ export namespace Components {
2828
'src'?: string;
2929
}
3030

31-
interface AppEditorToolbar {
32-
'blurSelectedElement': () => Promise<void>;
33-
'hideToolbar': () => Promise<void>;
34-
'touch': (element: HTMLElement) => Promise<void>;
35-
'unSelect': () => Promise<void>;
36-
}
37-
interface AppEditorToolbarAttributes extends StencilHTMLAttributes {
38-
'onBlockSlide'?: (event: CustomEvent<boolean>) => void;
39-
'onSlideDelete'?: (event: CustomEvent<HTMLElement>) => void;
40-
'onSlideDidChange'?: (event: CustomEvent<HTMLElement>) => void;
41-
}
42-
43-
interface AppFeed {}
44-
interface AppFeedAttributes extends StencilHTMLAttributes {}
45-
46-
interface AppFooter {}
47-
interface AppFooterAttributes extends StencilHTMLAttributes {}
48-
4931
interface AppLogo {}
5032
interface AppLogoAttributes extends StencilHTMLAttributes {}
5133

@@ -64,6 +46,29 @@ export namespace Components {
6446
'user'?: boolean;
6547
}
6648

49+
interface AppAddSlideAction {}
50+
interface AppAddSlideActionAttributes extends StencilHTMLAttributes {
51+
'onActionOpenSlideAdd'?: (event: CustomEvent<UIEvent>) => void;
52+
}
53+
54+
interface AppEditorToolbar {
55+
'blurSelectedElement': () => Promise<void>;
56+
'hideToolbar': () => Promise<void>;
57+
'touch': (element: HTMLElement) => Promise<void>;
58+
'unSelect': () => Promise<void>;
59+
}
60+
interface AppEditorToolbarAttributes extends StencilHTMLAttributes {
61+
'onBlockSlide'?: (event: CustomEvent<boolean>) => void;
62+
'onSlideDelete'?: (event: CustomEvent<HTMLElement>) => void;
63+
'onSlideDidChange'?: (event: CustomEvent<HTMLElement>) => void;
64+
}
65+
66+
interface AppFeed {}
67+
interface AppFeedAttributes extends StencilHTMLAttributes {}
68+
69+
interface AppFooter {}
70+
interface AppFooterAttributes extends StencilHTMLAttributes {}
71+
6772
interface AppPopular {}
6873
interface AppPopularAttributes extends StencilHTMLAttributes {}
6974

@@ -95,8 +100,8 @@ export namespace Components {
95100
interface AppHome {}
96101
interface AppHomeAttributes extends StencilHTMLAttributes {}
97102

98-
interface AppSlideAdd {}
99-
interface AppSlideAddAttributes extends StencilHTMLAttributes {}
103+
interface AppSlideType {}
104+
interface AppSlideTypeAttributes extends StencilHTMLAttributes {}
100105

101106
interface AppSlotType {
102107
'selectedElement': HTMLElement;
@@ -110,11 +115,12 @@ declare global {
110115
interface StencilElementInterfaces {
111116
'AppRoot': Components.AppRoot;
112117
'AppAvatar': Components.AppAvatar;
118+
'AppLogo': Components.AppLogo;
119+
'AppNavigation': Components.AppNavigation;
120+
'AppAddSlideAction': Components.AppAddSlideAction;
113121
'AppEditorToolbar': Components.AppEditorToolbar;
114122
'AppFeed': Components.AppFeed;
115123
'AppFooter': Components.AppFooter;
116-
'AppLogo': Components.AppLogo;
117-
'AppNavigation': Components.AppNavigation;
118124
'AppPopular': Components.AppPopular;
119125
'AppSlideNavigate': Components.AppSlideNavigate;
120126
'AppAbout': Components.AppAbout;
@@ -124,18 +130,19 @@ declare global {
124130
'AppTerms': Components.AppTerms;
125131
'AppEditor': Components.AppEditor;
126132
'AppHome': Components.AppHome;
127-
'AppSlideAdd': Components.AppSlideAdd;
133+
'AppSlideType': Components.AppSlideType;
128134
'AppSlotType': Components.AppSlotType;
129135
}
130136

131137
interface StencilIntrinsicElements {
132138
'app-root': Components.AppRootAttributes;
133139
'app-avatar': Components.AppAvatarAttributes;
140+
'app-logo': Components.AppLogoAttributes;
141+
'app-navigation': Components.AppNavigationAttributes;
142+
'app-add-slide-action': Components.AppAddSlideActionAttributes;
134143
'app-editor-toolbar': Components.AppEditorToolbarAttributes;
135144
'app-feed': Components.AppFeedAttributes;
136145
'app-footer': Components.AppFooterAttributes;
137-
'app-logo': Components.AppLogoAttributes;
138-
'app-navigation': Components.AppNavigationAttributes;
139146
'app-popular': Components.AppPopularAttributes;
140147
'app-slide-navigate': Components.AppSlideNavigateAttributes;
141148
'app-about': Components.AppAboutAttributes;
@@ -145,7 +152,7 @@ declare global {
145152
'app-terms': Components.AppTermsAttributes;
146153
'app-editor': Components.AppEditorAttributes;
147154
'app-home': Components.AppHomeAttributes;
148-
'app-slide-add': Components.AppSlideAddAttributes;
155+
'app-slide-type': Components.AppSlideTypeAttributes;
149156
'app-slot-type': Components.AppSlotTypeAttributes;
150157
}
151158

@@ -162,6 +169,24 @@ declare global {
162169
new (): HTMLAppAvatarElement;
163170
};
164171

172+
interface HTMLAppLogoElement extends Components.AppLogo, HTMLStencilElement {}
173+
var HTMLAppLogoElement: {
174+
prototype: HTMLAppLogoElement;
175+
new (): HTMLAppLogoElement;
176+
};
177+
178+
interface HTMLAppNavigationElement extends Components.AppNavigation, HTMLStencilElement {}
179+
var HTMLAppNavigationElement: {
180+
prototype: HTMLAppNavigationElement;
181+
new (): HTMLAppNavigationElement;
182+
};
183+
184+
interface HTMLAppAddSlideActionElement extends Components.AppAddSlideAction, HTMLStencilElement {}
185+
var HTMLAppAddSlideActionElement: {
186+
prototype: HTMLAppAddSlideActionElement;
187+
new (): HTMLAppAddSlideActionElement;
188+
};
189+
165190
interface HTMLAppEditorToolbarElement extends Components.AppEditorToolbar, HTMLStencilElement {}
166191
var HTMLAppEditorToolbarElement: {
167192
prototype: HTMLAppEditorToolbarElement;
@@ -180,18 +205,6 @@ declare global {
180205
new (): HTMLAppFooterElement;
181206
};
182207

183-
interface HTMLAppLogoElement extends Components.AppLogo, HTMLStencilElement {}
184-
var HTMLAppLogoElement: {
185-
prototype: HTMLAppLogoElement;
186-
new (): HTMLAppLogoElement;
187-
};
188-
189-
interface HTMLAppNavigationElement extends Components.AppNavigation, HTMLStencilElement {}
190-
var HTMLAppNavigationElement: {
191-
prototype: HTMLAppNavigationElement;
192-
new (): HTMLAppNavigationElement;
193-
};
194-
195208
interface HTMLAppPopularElement extends Components.AppPopular, HTMLStencilElement {}
196209
var HTMLAppPopularElement: {
197210
prototype: HTMLAppPopularElement;
@@ -246,10 +259,10 @@ declare global {
246259
new (): HTMLAppHomeElement;
247260
};
248261

249-
interface HTMLAppSlideAddElement extends Components.AppSlideAdd, HTMLStencilElement {}
250-
var HTMLAppSlideAddElement: {
251-
prototype: HTMLAppSlideAddElement;
252-
new (): HTMLAppSlideAddElement;
262+
interface HTMLAppSlideTypeElement extends Components.AppSlideType, HTMLStencilElement {}
263+
var HTMLAppSlideTypeElement: {
264+
prototype: HTMLAppSlideTypeElement;
265+
new (): HTMLAppSlideTypeElement;
253266
};
254267

255268
interface HTMLAppSlotTypeElement extends Components.AppSlotType, HTMLStencilElement {}
@@ -261,11 +274,12 @@ declare global {
261274
interface HTMLElementTagNameMap {
262275
'app-root': HTMLAppRootElement
263276
'app-avatar': HTMLAppAvatarElement
277+
'app-logo': HTMLAppLogoElement
278+
'app-navigation': HTMLAppNavigationElement
279+
'app-add-slide-action': HTMLAppAddSlideActionElement
264280
'app-editor-toolbar': HTMLAppEditorToolbarElement
265281
'app-feed': HTMLAppFeedElement
266282
'app-footer': HTMLAppFooterElement
267-
'app-logo': HTMLAppLogoElement
268-
'app-navigation': HTMLAppNavigationElement
269283
'app-popular': HTMLAppPopularElement
270284
'app-slide-navigate': HTMLAppSlideNavigateElement
271285
'app-about': HTMLAppAboutElement
@@ -275,18 +289,19 @@ declare global {
275289
'app-terms': HTMLAppTermsElement
276290
'app-editor': HTMLAppEditorElement
277291
'app-home': HTMLAppHomeElement
278-
'app-slide-add': HTMLAppSlideAddElement
292+
'app-slide-type': HTMLAppSlideTypeElement
279293
'app-slot-type': HTMLAppSlotTypeElement
280294
}
281295

282296
interface ElementTagNameMap {
283297
'app-root': HTMLAppRootElement;
284298
'app-avatar': HTMLAppAvatarElement;
299+
'app-logo': HTMLAppLogoElement;
300+
'app-navigation': HTMLAppNavigationElement;
301+
'app-add-slide-action': HTMLAppAddSlideActionElement;
285302
'app-editor-toolbar': HTMLAppEditorToolbarElement;
286303
'app-feed': HTMLAppFeedElement;
287304
'app-footer': HTMLAppFooterElement;
288-
'app-logo': HTMLAppLogoElement;
289-
'app-navigation': HTMLAppNavigationElement;
290305
'app-popular': HTMLAppPopularElement;
291306
'app-slide-navigate': HTMLAppSlideNavigateElement;
292307
'app-about': HTMLAppAboutElement;
@@ -296,7 +311,7 @@ declare global {
296311
'app-terms': HTMLAppTermsElement;
297312
'app-editor': HTMLAppEditorElement;
298313
'app-home': HTMLAppHomeElement;
299-
'app-slide-add': HTMLAppSlideAddElement;
314+
'app-slide-type': HTMLAppSlideTypeElement;
300315
'app-slot-type': HTMLAppSlotTypeElement;
301316
}
302317

0 commit comments

Comments
 (0)