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

Commit

Permalink
feat(#471): type definition for poll
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Nov 18, 2019
1 parent da47dc2 commit 23e4b28
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 179 deletions.
13 changes: 9 additions & 4 deletions studio/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"web-social-share": "^6.2.0"
},
"devDependencies": {
"@deckdeckgo/types": "^1.0.0-rc.3",
"@deckdeckgo/types": "file:../utils/types",
"@stencil/core": "^1.7.5",
"@stencil/postcss": "^1.0.1",
"@stencil/sass": "^1.1.1",
Expand Down
15 changes: 0 additions & 15 deletions studio/src/app/models/poll/poll.tsx

This file was deleted.

15 changes: 9 additions & 6 deletions studio/src/app/pages/core/app-poll/app-poll.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {Component, h, Prop, State} from '@stencil/core';

import {Poll} from '../../../models/poll/poll';
import {Subscription} from 'rxjs';

import {DeckdeckgoPoll, DeckdeckgoPollAnswer} from '@deckdeckgo/types';

import {PollService} from '../../../services/poll/poll.service';
import {Subscription} from 'rxjs';

@Component({
tag: 'app-poll',
Expand All @@ -15,7 +16,7 @@ export class AppPoll {
pollKey: string;

@State()
private poll: Poll;
private poll: DeckdeckgoPoll;

@State()
private choice: string;
Expand Down Expand Up @@ -43,7 +44,7 @@ export class AppPoll {
}

async componentWillLoad() {
this.subscription = this.pollService.watch().subscribe((poll: Poll) => {
this.subscription = this.pollService.watch().subscribe((poll: DeckdeckgoPoll) => {
this.poll = poll;
this.pollNotFound = this.pollKey && (!poll || poll === undefined);

Expand Down Expand Up @@ -80,6 +81,8 @@ export class AppPoll {

// TODO: What do do if error, hasVoted = true?

// TODO: local db has voted => don't allow multiple vote

this.hasVoted = true;
}

Expand Down Expand Up @@ -141,10 +144,10 @@ export class AppPoll {
return undefined;
}

return this.poll.poll.values.map((choice) => {
return this.poll.poll.values.map((choice: DeckdeckgoPollAnswer) => {
return (
<ion-item>
<ion-label>{choice.title}</ion-label>
<ion-label>{choice.label}</ion-label>
<ion-radio slot="start" value={choice.key} mode="md"></ion-radio>
</ion-item>
)
Expand Down
10 changes: 5 additions & 5 deletions studio/src/app/services/poll/poll.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import * as io from 'socket.io-client';
import {BehaviorSubject, Observable} from 'rxjs';
import {take} from 'rxjs/operators';

import {Poll} from '../../models/poll/poll';
import {DeckdeckgoPoll} from '@deckdeckgo/types';

export class PollService {

private socket: SocketIOClient.Socket;

private poll: BehaviorSubject<Poll | undefined> = new BehaviorSubject<Poll|undefined>(undefined);
private poll: BehaviorSubject<DeckdeckgoPoll | undefined> = new BehaviorSubject<DeckdeckgoPoll|undefined>(undefined);

private static instance: PollService;

Expand Down Expand Up @@ -43,7 +43,7 @@ export class PollService {
this.socket.emit('join', {key: pollKey});
});

this.socket.on('poll_desc', async (data) => {
this.socket.on('poll_desc', async (data: DeckdeckgoPoll) => {
this.poll.next(data);
});

Expand Down Expand Up @@ -74,7 +74,7 @@ export class PollService {
return;
}

this.watch().pipe(take(1)).subscribe((poll: Poll) => {
this.watch().pipe(take(1)).subscribe((poll: DeckdeckgoPoll) => {
if (poll) {
this.socket.emit('leave', {
key: poll.key
Expand All @@ -89,7 +89,7 @@ export class PollService {
});
}

watch(): Observable<Poll | undefined> {
watch(): Observable<DeckdeckgoPoll | undefined> {
return this.poll.asObservable();
}

Expand Down
17 changes: 17 additions & 0 deletions utils/types/src/chart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// A bar
export interface DeckdeckgoBarChartDataValue {
// The key of a bar, use for the style
key: number | string;
// A title for the bar
label: string;
// Its value
value: number;
}

// A chart
export interface DeckdeckgoBarChartData {
// The chart label
label: string | Date | number;
// 1 or multiple bars
values: DeckdeckgoBarChartDataValue[];
}
99 changes: 3 additions & 96 deletions utils/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,96 +1,3 @@
export enum DeckdeckgoDrawAction {
PENCIL,
CIRCLE
}

export enum DeckdeckgoSlideAction {
PLAY = 'play',
PAUSE = 'pause'
}

export interface DeckdeckgoAttributeDefinition {
name: string;
value?: any;
}

export interface DeckdeckgoSlideDefinition {
template: string;
content?: string;
attributes?: DeckdeckgoAttributeDefinition[];
}

export interface DeckdeckgoDeckDefinition {
slides: DeckdeckgoSlideDefinition[];
attributes?: DeckdeckgoAttributeDefinition[];
background?: string;

reveal: boolean;
revealOnMobile: boolean;
}

export enum DeckdeckgoEventType {
SLIDES_REQUEST = 'slides_request',
SLIDES_ANSWER = 'slides_answer',
DECK_UPDATE = 'deck_update',
SLIDE_UPDATE = 'slide_update',
NEXT_SLIDE = 'next_slide',
PREV_SLIDE = 'prev_slide',
SLIDE_TO = 'slide_to',
CLEAR_SLIDE = 'clear_slide',
START_DRAWING = 'start_drawing',
DRAW = 'draw',
END_DRAWING = 'end_drawing',
SLIDE_ACTION = 'slide_action',
DELETE_SLIDE = 'delete_slide',
DECK_REVEAL_UPDATE = 'deck_reveal_update'
}

export enum DeckdeckgoEventEmitter {
DECK = 'deck',
APP = 'app'
}

export interface DeckdeckgoEvent {
type: DeckdeckgoEventType;
emitter: DeckdeckgoEventEmitter
}

export interface DeckdeckgoEventDraw extends DeckdeckgoEvent {
action: DeckdeckgoDrawAction;

clientX: number;
clientY: number;

windowWidth: number;
windowHeight: number;

color?: string;
}

export interface DeckdeckgoEventNextPrevSlide extends DeckdeckgoEvent {
slideAnimation: boolean;
}

export interface DeckdeckgoEventDeckReveal extends DeckdeckgoEvent {
reveal: boolean;
}

export interface DeckdeckgoEventSlideTo extends DeckdeckgoEvent {
index: number;
speed?: number
}

export interface DeckdeckgoEventDeck extends DeckdeckgoEvent {
length: number;
mobile: boolean;
deck: DeckdeckgoDeckDefinition;
}

export interface DeckdeckgoEventSlide extends DeckdeckgoEvent {
index: number;
slide: DeckdeckgoSlideDefinition;
}

export interface DeckdeckgoEventSlideAction extends DeckdeckgoEvent {
action: DeckdeckgoSlideAction;
}
export * from './remote';
export * from './chart';
export * from './poll';
14 changes: 14 additions & 0 deletions utils/types/src/poll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface DeckdeckgoPollAnswer {
key: number | string;
label: string;
}

export interface DeckdeckgoPollQuestion {
label: string;
values: DeckdeckgoPollAnswer[];
}

export interface DeckdeckgoPoll {
key: string;
poll: DeckdeckgoPollQuestion;
}
96 changes: 96 additions & 0 deletions utils/types/src/remote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
export enum DeckdeckgoDrawAction {
PENCIL,
CIRCLE
}

export enum DeckdeckgoSlideAction {
PLAY = 'play',
PAUSE = 'pause'
}

export interface DeckdeckgoAttributeDefinition {
name: string;
value?: any;
}

export interface DeckdeckgoSlideDefinition {
template: string;
content?: string;
attributes?: DeckdeckgoAttributeDefinition[];
}

export interface DeckdeckgoDeckDefinition {
slides: DeckdeckgoSlideDefinition[];
attributes?: DeckdeckgoAttributeDefinition[];
background?: string;

reveal: boolean;
revealOnMobile: boolean;
}

export enum DeckdeckgoEventType {
SLIDES_REQUEST = 'slides_request',
SLIDES_ANSWER = 'slides_answer',
DECK_UPDATE = 'deck_update',
SLIDE_UPDATE = 'slide_update',
NEXT_SLIDE = 'next_slide',
PREV_SLIDE = 'prev_slide',
SLIDE_TO = 'slide_to',
CLEAR_SLIDE = 'clear_slide',
START_DRAWING = 'start_drawing',
DRAW = 'draw',
END_DRAWING = 'end_drawing',
SLIDE_ACTION = 'slide_action',
DELETE_SLIDE = 'delete_slide',
DECK_REVEAL_UPDATE = 'deck_reveal_update'
}

export enum DeckdeckgoEventEmitter {
DECK = 'deck',
APP = 'app'
}

export interface DeckdeckgoEvent {
type: DeckdeckgoEventType;
emitter: DeckdeckgoEventEmitter
}

export interface DeckdeckgoEventDraw extends DeckdeckgoEvent {
action: DeckdeckgoDrawAction;

clientX: number;
clientY: number;

windowWidth: number;
windowHeight: number;

color?: string;
}

export interface DeckdeckgoEventNextPrevSlide extends DeckdeckgoEvent {
slideAnimation: boolean;
}

export interface DeckdeckgoEventDeckReveal extends DeckdeckgoEvent {
reveal: boolean;
}

export interface DeckdeckgoEventSlideTo extends DeckdeckgoEvent {
index: number;
speed?: number
}

export interface DeckdeckgoEventDeck extends DeckdeckgoEvent {
length: number;
mobile: boolean;
deck: DeckdeckgoDeckDefinition;
}

export interface DeckdeckgoEventSlide extends DeckdeckgoEvent {
index: number;
slide: DeckdeckgoSlideDefinition;
}

export interface DeckdeckgoEventSlideAction extends DeckdeckgoEvent {
action: DeckdeckgoSlideAction;
}
11 changes: 11 additions & 0 deletions webcomponents/charts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions webcomponents/charts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"date-fns": "^2.5.1"
},
"devDependencies": {
"@deckdeckgo/types": "file:../../utils/types",
"@stencil/core": "^1.7.3",
"@stencil/postcss": "^1.0.1",
"@stencil/sass": "^1.0.1",
Expand Down
Loading

0 comments on commit 23e4b28

Please sign in to comment.