From dcf07f60c045f4cca410720b9738b26e1d952bfd Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Tue, 4 Sep 2018 21:53:56 -0700 Subject: [PATCH] Convert media reducer to Typescript --- js/reducers/{media.js => media.ts} | 3 +- js/types.ts | 56 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) rename js/reducers/{media.js => media.ts} (95%) diff --git a/js/reducers/media.js b/js/reducers/media.ts similarity index 95% rename from js/reducers/media.js rename to js/reducers/media.ts index 901b8981..5a3cd9db 100644 --- a/js/reducers/media.js +++ b/js/reducers/media.ts @@ -1,3 +1,4 @@ +import { MediaState, Action } from "../types"; import { PLAY, STOP, @@ -16,7 +17,7 @@ import { } from "../actionTypes"; import { TIME_MODE, MEDIA_STATUS } from "../constants"; -const media = (state, action) => { +const media = (state: MediaState, action: Action): MediaState => { if (!state) { return { timeMode: TIME_MODE.ELAPSED, diff --git a/js/types.ts b/js/types.ts index 69e30eab..d2030c18 100644 --- a/js/types.ts +++ b/js/types.ts @@ -13,6 +13,48 @@ export type Action = | { type: "SET_AVAILABLE_SKINS"; skins: Array; + } + | { + type: "PLAY"; + } + | { + type: "IS_PLAYING"; + } + | { + type: "PAUSE"; + } + | { + type: "STOP"; + } + | { + type: "IS_STOPPED"; + } + | { + type: "CHANNEL_COUNT_CHANGED"; + channels: number; + } | { + type: "TOGGLE_TIME_MODE"; + } | { + type: "UPDATE_TIME_ELAPSED"; + elapsed: number; + } | { + type: "ADD_TRACK_FROM_URL"; + } | { + type: "SET_MEDIA"; + length: number; + kbps: number; + khz: number; + channels: number; + } | { + type: "SET_VOLUME"; + volume: number; + } | { + type: "SET_BALANCE"; + balance: number; + } | { + type: "TOGGLE_REPEAT"; + } | { + type: "TOGGLE_SHUFFLE"; }; export interface SettingsState { @@ -22,3 +64,17 @@ export interface SettingsState { export interface NetworkState { connected: boolean; } + +export interface MediaState { + timeMode: string; // TODO: Convert this to an enum + timeElapsed: number; + length: number | null; + kbps: number| null; + khz: number | null; + volume: number; + balance: number; + channels: number | null; // TODO: Convert this to an enum + shuffle: boolean; + repeat: boolean; + status: string | null; // TODO: Convert this to an enum +}