Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move components to TS #2 #438

Merged
merged 59 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
487fc5c
Move loaders to TS
raphaelvigee Aug 4, 2019
5a9f607
Move VolumeControl to TS
raphaelvigee Aug 4, 2019
d65c2a5
Move player to TS
raphaelvigee Aug 5, 2019
90ccca4
Move Translations to TS
raphaelvigee Aug 5, 2019
808a787
Move tabs to TS
raphaelvigee Aug 5, 2019
f00c1b8
Move Splashscreen to TS
raphaelvigee Aug 5, 2019
88c6436
Move TrackContextMenu to TS
raphaelvigee Aug 5, 2019
bcae48e
Move ItemList to TS
raphaelvigee Aug 5, 2019
9f3f6f7
Move AlbumItem to TS
raphaelvigee Aug 5, 2019
ccc7641
Move lbumContextMenu to TS
raphaelvigee Aug 5, 2019
f3d7362
Move AlbumPanel to TS
raphaelvigee Aug 5, 2019
b6ac786
Move NavigationBar to TS
raphaelvigee Aug 5, 2019
0034e4c
Move Rating to TS
raphaelvigee Aug 5, 2019
6b0a403
Move TopCharts to TS
raphaelvigee Aug 5, 2019
4965f82
Move MenuItem to TS
raphaelvigee Aug 5, 2019
d584946
Move PlaylistContextMenu to TS
raphaelvigee Aug 5, 2019
39656f8
Move contextmenu & tracklistitem to TS
raphaelvigee Aug 5, 2019
aabf253
Move artistItem to TS
raphaelvigee Aug 5, 2019
b12c052
Move resultItem to TS
raphaelvigee Aug 5, 2019
e776514
Move searchbar to TS
raphaelvigee Aug 6, 2019
97674d8
Move CuratorItem to TS
raphaelvigee Aug 7, 2019
9dbf731
Move ArtistAlbums to TS
raphaelvigee Aug 7, 2019
76de499
Move ArtistsList to TS
raphaelvigee Aug 9, 2019
4cb6727
Move GenteItem to TS
raphaelvigee Aug 9, 2019
c91a52a
Move PlaylistItem to TS
raphaelvigee Aug 9, 2019
eadddbc
Move some more stuff to TS
raphaelvigee Aug 10, 2019
40b6cb6
Move AuthorizeProvider to TS
raphaelvigee Aug 15, 2019
b38649a
Move SongsPage to TS
raphaelvigee Aug 15, 2019
eee86f6
Move Sidebar & PlaylistProvider to TS
raphaelvigee Aug 15, 2019
f51a031
Move SidebarMenu to TS
raphaelvigee Aug 15, 2019
a5c16f0
Move Lyrics & LyricsMOdal to TS
raphaelvigee Aug 15, 2019
f965717
Move MusicKitProvider to TS
raphaelvigee Aug 15, 2019
ea16072
Move PageContent to TS
raphaelvigee Aug 15, 2019
c737bcc
Move RadioPage to TS
raphaelvigee Aug 15, 2019
9d30793
Move PlaylistSelectcor to TS
raphaelvigee Aug 15, 2019
29c4260
Move PlaylistPanel to TS
raphaelvigee Aug 15, 2019
b19cc0a
Move PlaylistPage to TS
raphaelvigee Aug 15, 2019
1783ca5
Move PlaylistsPage to TS & fix HOCs
raphaelvigee Aug 15, 2019
d350481
Move SentryBoundary to TS
raphaelvigee Aug 15, 2019
d65d1ab
Move GAProvider to TS
raphaelvigee Aug 15, 2019
8df1db1
Move LastfmProvider to TS
raphaelvigee Aug 15, 2019
46de869
Move Genres to TS
raphaelvigee Aug 15, 2019
cac7a48
Move GenrePage to TS
raphaelvigee Aug 15, 2019
ac2f5bf
Move ForYouPage to TS
raphaelvigee Aug 15, 2019
f96f026
Move BrowsePage to TS
raphaelvigee Aug 15, 2019
74efeab
Move AuthorizeButton to TS
raphaelvigee Aug 15, 2019
30f70ff
Move ArtistPage to TS
raphaelvigee Aug 15, 2019
def85d5
Move ArtistsPage to TS
raphaelvigee Aug 15, 2019
1b8a61e
Move AlbumsPage to TS
raphaelvigee Aug 15, 2019
ba07836
Move Settings to TS
raphaelvigee Aug 15, 2019
b204275
Move SearchPage to TS
raphaelvigee Aug 15, 2019
48d4fd3
Move RecentlyAdded to TS
raphaelvigee Aug 15, 2019
e87de68
Move Layout to TS
raphaelvigee Aug 15, 2019
eb3b350
MOve App to TS
raphaelvigee Aug 15, 2019
ff155f9
Move index to TS
raphaelvigee Aug 15, 2019
13ae907
Move AlbumPage to TS
raphaelvigee Aug 15, 2019
8194e52
Move remainig js to ts & disallow js
raphaelvigee Aug 15, 2019
8a3eaf4
Disable Interface starting with capitalized I
raphaelvigee Aug 16, 2019
10c8d8b
Prevent type copy/paste
raphaelvigee Aug 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move LastfmProvider to TS
  • Loading branch information
raphaelvigee committed Aug 15, 2019
commit 8df1db1e5cd24144d146783644df4e3c0eac8bb0
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
"@symfony/webpack-encore": "^0.27.0",
"@types/classnames": "^2.2.7",
"@types/hoist-non-react-statics": "^3.3.1",
"@types/js-md5": "^0.4.2",
"@types/lodash": "^4.14.136",
"@types/mousetrap": "^1.6.3",
"@types/prop-types": "^15.7.1",
"@types/qs": "^6.5.3",
"@types/react": "^16.8.18",
"@types/react-dom": "^16.8.4",
"@types/react-router-dom": "^4.3.4",
"@types/react-s-alert": "^1.3.2",
"@types/react-virtualized": "^9.21.1",
"axios": "^0.18.0",
"classnames": "^2.2.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import axios, { AxiosRequestConfig } from 'axios';
import md5 from 'js-md5';
import axios from 'axios';
import qs from 'qs';
import React, { ReactNode, useEffect, useState } from 'react';
import Alert from 'react-s-alert';
import withMK from '../../hoc/withMK';
import translate from '../../utils/translations/Translations';

const apikey = process.env.LASTFM_API_KEY;
const secret = process.env.LASTFM_SECRET;

const SK_STORAGE_KEY = 'lastfm_sk';

interface ILastfmProviderProps extends IMKProps {
children: ReactNode;
}

export interface ILastfmProviderValue {
login: () => void;
reset: () => void;
connected: boolean;
}

function getSK() {
return localStorage.getItem('lastfm_sk');
return localStorage.getItem(SK_STORAGE_KEY);
}

export const LastfmContext = React.createContext({ connected: !!getSK() });
export const LastfmContext = React.createContext<ILastfmProviderValue>({
connected: !!getSK(),
login: () => undefined,
reset: () => undefined,
});

function LastfmProvider({ children, mk }) {
const [connected, setConnected] = useState(!!getSK());
const LastfmProvider: React.FC<ILastfmProviderProps> = ({ children, mk }: ILastfmProviderProps) => {
const [connected, setConnected] = useState(() => !!getSK());

async function request(isWrite, method, callParams = {}, sk = true) {
const params = {
async function request(isWrite: boolean, method: string, callParams = {}, sk = true) {
const params: any = {
...callParams,
method,
api_key: apikey,
Expand All @@ -33,7 +48,7 @@ function LastfmProvider({ children, mk }) {
params.api_sig = sign(params);
params.format = 'json';

const config = {
const config: AxiosRequestConfig = {
url: 'https://ws.audioscrobbler.com/2.0/',
};

Expand All @@ -50,7 +65,7 @@ function LastfmProvider({ children, mk }) {
return data;
}

async function scrobble(item) {
async function scrobble(item: MusicKit.MediaItem) {
const params = {
'artist[0]': item.artistName,
'track[0]': item.title,
Expand All @@ -77,7 +92,7 @@ function LastfmProvider({ children, mk }) {
}
}

function sign(params) {
function sign(params: any) {
const str = Object.keys(params)
.sort()
.reduce((result, key) => `${result}${key}${params[key]}`, '');
Expand All @@ -94,22 +109,22 @@ function LastfmProvider({ children, mk }) {
window.location.href = `http://www.last.fm/api/auth/?api_key=${apikey}&cb=${cb}`;
}

async function fetchSK(token) {
async function fetchSK(token: string) {
const params = {
token,
};

const data = await request(true, 'auth.getSession', params, false);

localStorage.setItem('lastfm_sk', data.session.key);
localStorage.setItem(SK_STORAGE_KEY, data.session.key);

setConnected(true);
}

function reset() {
setConnected(false);

localStorage.removeItem('lastfm_sk');
localStorage.removeItem(SK_STORAGE_KEY);
}

async function fetchToken() {
Expand Down Expand Up @@ -153,18 +168,13 @@ function LastfmProvider({ children, mk }) {
}
}, [mk.mediaItem]);

const state = {
const state: ILastfmProviderValue = {
login,
reset,
connected,
};

return <LastfmContext.Provider value={state}>{children}</LastfmContext.Provider>;
}

LastfmProvider.propTypes = {
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
mk: PropTypes.any.isRequired,
};

const bindings = {
Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,11 @@
"@types/react" "*"
hoist-non-react-statics "^3.3.0"

"@types/js-md5@^0.4.2":
version "0.4.2"
resolved "https://registry.yarnpkg.com/@types/js-md5/-/js-md5-0.4.2.tgz#95b39911e2081bf2915436e61cc345e12459e5bb"
integrity sha512-FUPoQkpQTzA5wz9ebrdVRjsjQsFehr+cW1CVhLcI2UwD/SO/4NHPO1esrXPPbx7ux762U0POmWFSrUjQq2ophw==

"@types/lodash@^4.14.136":
version "4.14.136"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.136.tgz#413e85089046b865d960c9ff1d400e04c31ab60f"
Expand All @@ -848,6 +853,11 @@
version "1.5.1"
resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.1.tgz#48fd98c1561fe718b61733daed46ff115b496e18"

"@types/qs@^6.5.3":
version "6.5.3"
resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.5.3.tgz#1c3b71b091eaeaf5924538006b7f70603ce63d38"
integrity sha512-Jugo5V/1bS0fRhy2z8+cUAHEyWOATaz4rbyLVvcFs7+dXp5HfwpEwzF1Q11bB10ApUqHf+yTauxI0UXQDwGrbA==

"@types/react-dom@^16.8.4":
version "16.8.4"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.8.4.tgz#7fb7ba368857c7aa0f4e4511c4710ca2c5a12a88"
Expand All @@ -871,6 +881,13 @@
"@types/history" "*"
"@types/react" "*"

"@types/react-s-alert@^1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@types/react-s-alert/-/react-s-alert-1.3.2.tgz#02a0879c83c64f9b8f89053f1879588341109c23"
integrity sha512-rrq6WpNtyGLxGMP+eGlLLBOdojHhZWDEbNrLlBca0BkOIuamtfFigkIbPnmVAFkzOcTED3mFuKmYu58D+IIUfQ==
dependencies:
"@types/react" "*"

"@types/react-virtualized@^9.21.1":
version "9.21.1"
resolved "https://registry.yarnpkg.com/@types/react-virtualized/-/react-virtualized-9.21.1.tgz#c85770f5bb0ccaeb3496d97ff2a2d9028c8ed1fd"
Expand Down