Replace interfaces with Types

This commit is contained in:
Anders Ytterström 2020-03-05 18:09:48 +01:00 committed by Anders Ytterström
parent cb9f3ec3d1
commit 6ba958fafa
12 changed files with 45 additions and 34 deletions

View file

@ -2,7 +2,7 @@ import React from "react";
import Album from "./album"; import Album from "./album";
import * as interfaces from "../interfaces"; import * as interfaces from "../interfaces";
export default (props: AlbumList) => { export default (props: Props) => {
const { albums, handleOnClick, blurred } = props; const { albums, handleOnClick, blurred } = props;
const classNames = blurred ? "blur" : ""; const classNames = blurred ? "blur" : "";
return ( return (
@ -18,8 +18,8 @@ export default (props: AlbumList) => {
); );
}; };
interface AlbumList { type Props = {
albums: Array<interfaces.Album>; albums: Array<interfaces.Album>;
handleOnClick: Function; handleOnClick: Function;
blurred: boolean; blurred: boolean;
} };

View file

@ -1,7 +1,7 @@
import React from "react"; import React from "react";
import * as interfaces from "../interfaces"; import { Album } from "../interfaces";
export default (props: Album) => { export default (props: Props) => {
const handleKeyPress = (e: KeyboardEvent, callback: Function) => { const handleKeyPress = (e: KeyboardEvent, callback: Function) => {
const SPACE_KEY = 32; const SPACE_KEY = 32;
const ENTER_KEY = 13; const ENTER_KEY = 13;
@ -37,7 +37,8 @@ export default (props: Album) => {
); );
}; };
interface Album { type Props = {
album: interfaces.Album; key: number;
album: Album;
handleOnClick: Function; handleOnClick: Function;
} };

View file

@ -1,6 +1,6 @@
import React from "react"; import React from "react";
export default (props: FilterInput) => { export default (props: Props) => {
const { value, handleOnChange } = props; const { value, handleOnChange } = props;
return ( return (
<div> <div>
@ -14,7 +14,7 @@ export default (props: FilterInput) => {
); );
}; };
interface FilterInput { type Props = {
value: string; value: string;
handleOnChange: Function; handleOnChange: Function;
} };

View file

@ -1,12 +1,7 @@
import React from "react"; import React from "react";
import { Album } from "../interfaces"; import { Album } from "../interfaces";
interface Modal { export default (props: Props) => {
album: Album;
handleOnClick: Function;
}
export default (props: Modal) => {
const handleKeyPress = (e: KeyboardEvent, callback: Function) => { const handleKeyPress = (e: KeyboardEvent, callback: Function) => {
console.log(e.charCode); console.log(e.charCode);
callback(); callback();
@ -40,3 +35,8 @@ export default (props: Modal) => {
</div> </div>
); );
}; };
type Props = {
album: Album;
handleOnClick(): void;
};

View file

@ -1,6 +1,6 @@
import React from "react"; import React from "react";
export default (props: SortSelect) => { export default (props: Props) => {
const { value, handleOnChange } = props; const { value, handleOnChange } = props;
return ( return (
<div hidden> <div hidden>
@ -18,7 +18,7 @@ export default (props: SortSelect) => {
); );
}; };
interface SortSelect { type Props = {
value: string; value: string;
handleOnChange: Function; handleOnChange: Function;
} };

View file

@ -1,4 +1,3 @@
import React from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import Modal from "../components/modal"; import Modal from "../components/modal";
import { unselectAlbum } from "../actions"; import { unselectAlbum } from "../actions";

View file

@ -1,4 +1,3 @@
import React from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import SortSelect from "../components/sort-select"; import SortSelect from "../components/sort-select";
import { setSortKey } from "../actions"; import { setSortKey } from "../actions";

View file

@ -1,14 +1,14 @@
import { LOAD_ALBUMS_OK } from "../actions"; import { LOAD_ALBUMS_OK } from "../actions";
import { Album } from "../interfaces"; import { Album } from "../interfaces";
interface AlbumsAction { type Action = {
type: string; type: string;
payload: { payload: {
albums: Array<Album>; albums: Array<Album>;
}; };
} };
export default (state: Array<Album> = [], action: AlbumsAction) => { export default (state: Array<Album> = [], action: Action) => {
switch (action.type) { switch (action.type) {
case LOAD_ALBUMS_OK: case LOAD_ALBUMS_OK:
const { albums } = action.payload; const { albums } = action.payload;

View file

@ -0,0 +1,12 @@
import { combineReducers } from "redux";
import albums from "./albums";
import visibilityFilter from "./visibility-filter";
import sortKey from "./sort-key";
import selectedAlbum from "./selected-album";
export default combineReducers({
albums,
visibilityFilter,
sortKey,
selectedAlbum
});

View file

@ -1,14 +1,14 @@
import { SELECT_ALBUM, UNSELECT_ALBUM } from "../actions"; import { SELECT_ALBUM, UNSELECT_ALBUM } from "../actions";
import { Album } from "../interfaces"; import { Album } from "../interfaces";
interface AlbumAction { type Action = {
type: string; type: string;
payload: { payload: {
album: Album; album: Album;
}; };
} };
export default (state: Object = {}, action: AlbumAction) => { export default (state: Object = {}, action: Action) => {
switch (action.type) { switch (action.type) {
case SELECT_ALBUM: case SELECT_ALBUM:
return action.payload.album; return action.payload.album;

View file

@ -1,13 +1,13 @@
import { SET_SORT_KEY } from "../actions"; import { SET_SORT_KEY } from "../actions";
interface SortKeyAction { type Action = {
type: string; type: string;
payload: { payload: {
key: string; key: string;
}; };
} };
export default (state: string = "id", action: SortKeyAction) => { export default (state: string = "id", action: Action) => {
switch (action.type) { switch (action.type) {
case SET_SORT_KEY: case SET_SORT_KEY:
return action.payload.key; return action.payload.key;

View file

@ -1,13 +1,13 @@
import { SET_VISIBILITY_FILTER } from "../actions"; import { SET_VISIBILITY_FILTER } from "../actions";
interface VisibilityFilterAction { type Action = {
type: string; type: string;
payload: { payload: {
filter: string; filter: string;
}; };
} };
export default (state: string = "", action: VisibilityFilterAction) => { export default (state: string = "", action: Action) => {
switch (action.type) { switch (action.type) {
case SET_VISIBILITY_FILTER: case SET_VISIBILITY_FILTER:
return action.payload.filter; return action.payload.filter;