Skip to content

Commit

Permalink
Merge pull request #14 from TriPSs/redux-clazz
Browse files Browse the repository at this point in the history
WIP: Redux clazz + bug fixes and improvments
  • Loading branch information
TriPSs authored Aug 4, 2017
2 parents 3a46a14 + 34a6665 commit a7169c5
Show file tree
Hide file tree
Showing 166 changed files with 5,963 additions and 4,628 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"react"
],
"plugins": [
"transform-decorators-legacy",
"add-module-exports",
"dynamic-import-webpack"
],
Expand Down
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"jsx-a11y/img-redundant-alt": [2],
"jsx-a11y/aria-role": [2],
"jsx-a11y/no-access-key": [2],
"jsx-a11y/href-no-hash": "off",

"class-methods-use-this": "off",
"fp/no-arguments": "off",
Expand All @@ -155,6 +156,7 @@
"fp/no-unused-expression": "off",
"fp/no-valueof-field": "off",
"import/no-extraneous-dependencies": "off",
"import/no-named-as-default": 0,
"no-var": "off",
"no-let": "off",
"no-plusplus": "off",
Expand Down
37 changes: 33 additions & 4 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
{
"extends": "stylelint-config-standard",
"rules": {
"color-hex-case": "upper",
"rules": {
"color-hex-case": "lower",
"selector-pseudo-element-colon-notation": "single",
"selector-pseudo-class-no-unknown": [true, {"ignorePseudoClasses": ["global"]}],
"indentation": null
"selector-pseudo-class-no-unknown": [
true,
{
"ignorePseudoClasses": [
"global"
]
}
],
"indentation": null,
"at-rule-no-unknown": [
true,
{
"ignoreAtRules": [
"extend",
"at-root",
"debug",
"warn",
"error",
"if",
"else",
"for",
"each",
"while",
"mixin",
"include",
"content",
"return",
"function"
]
}
]
}
}
49 changes: 34 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
dist: trusty
sudo: false

language: node_js
node_js: "8"

node_js:
- 8
os:
- linux
- osx

cache:
yarn: true
directories:
- node_modules
- app/node_modules
- node_modules
- app/node_modules
- $HOME/.cache/electron
- $HOME/.cache/electron-builder
- $HOME/.npm/_prebuilds

env:
global:
- ELECTRON_CACHE=$HOME/.cache/electron
- ELECTRON_BUILDER_CACHE=$HOME/.cache/electron-builder

branches:
only:
- master
- develop

addons:
apt:
Expand All @@ -21,20 +36,24 @@ addons:
- graphicsmagick
- xz-utils
- xorriso
- libsecret-1-0

before_install:
- npm i -g greenkeeper-lockfile@1

install:
- export CXX="g++-4.8"
- yarn
- cd app && yarn && cd ..
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16"
- npm i
- cd app && npm i && cd ..
# - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16"

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start &
- sleep 3
- greenkeeper-lockfile-update

script:
- npm run lint:check
# - npm run test
- npm run package
# - npm run test-e2e
# - npm run test
- npm run package:ci
# - npm run test-e2e

after_script:
- greenkeeper-lockfile-upload
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 David Zukowski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<h3 align="center">A Modern and Experimental Popcorn Time Client</h3>

<div align="center">
<a target="_blank" href="https://travis-ci.org/tripss/popcorn-time-desktop/">
<img src="https://img.shields.io/travis/tripss/popcorn-time-desktop/master.svg?maxAge=86400" alt="Travis Build branch" />
<a target="_blank" href="https://travis-ci.org/TriPSs/popcorn-time-desktop/">
<img src="https://img.shields.io/travis/TriPSs/popcorn-time-desktop/master.svg?maxAge=86400" alt="Travis Build branch" />
</a>
<a target="_blank" href="https://ci.appveyor.com/project/tripss/popcorn-time-desktop/branch/master">
<img src="https://ci.appveyor.com/api/projects/status/071qeglg94au8wr2/branch/master?svg=true&maxAge=86400" alt="AppVeyor Build status" />
Expand Down
68 changes: 38 additions & 30 deletions app/api/Butter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/**
* The highest level abstraction layer for querying torrents and metadata
* @flow
*/
import MetadataAdapter from './Metadata/MetadataAdapter'
// @flow
import MetadataAdapter from './Metadata'
import PctTorrentProvider from './Torrents/PctTorrentProvider'
import TorrentAdapter from './Torrents'

export class Butter {
export default new (class {

metadataAdapter: MetadataAdapter

Expand All @@ -16,30 +13,41 @@ export class Butter {

constructor() {
this.pctAdapter = new PctTorrentProvider()
this.metadataAdapter = new MetadataAdapter()
this.torrentAdapter = new TorrentAdapter()
this.metadataAdapter = new MetadataAdapter()
}

getMovies = (page: number = 1, filters = {}) => this.pctAdapter.getMovies(page, filters)

getMovie = (itemId: string) => this.pctAdapter.getMovie(itemId)

getShows = (page: number = 1, filters = {}) => this.pctAdapter.getShows(page, filters)

getShow = (itemId: string) => this.pctAdapter.getShow(itemId)
.then(pctShow => this.metadataAdapter
.getSeasons(pctShow.id, pctShow.seasons)
.then(seasons => ({
...pctShow,
seasons,
})))

searchEpisode = (...args) => this.torrentAdapter.searchEpisode(...args)

search = (...args) => this.torrentAdapter.search(...args)

}

export const instance = new Butter()

export default instance
getMovies = (page: number = 1, filters: Object = {}) => (
this.pctAdapter.getMovies(page, filters)
)

getMovie = (itemId: string) => (
this.pctAdapter.getMovie(itemId)
)

getShows = (page: number = 1, filters: Object = {}) => (
this.pctAdapter.getShows(page, filters)
)

getShow = (itemId: string) => (
this.pctAdapter
.getShow(itemId)
.then(pctShow => (
this.metadataAdapter
.getSeasons(itemId, pctShow.seasons)
.then(seasons => ({
...pctShow,
seasons,
}))),
)
)

searchEpisode = (...args) => (
this.torrentAdapter.searchEpisode(...args)
)

search = (...args) => (
this.torrentAdapter.search(...args)
)

})()
26 changes: 19 additions & 7 deletions app/api/Database/Watched/WatchedDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,33 @@ export class WatchedDB {
resolve(),
))

markMovieWatched = (id: string) =>
this.markWatched({ id, type: 'movie' })
markMovieWatched = (id: string) => this.markWatched({ id, type: 'movie' })

markMovieUnWatched = (id: string) => this.unmarkWatched({ id, type: 'movie' })

getMoviesWatched = () => new Promise(resolve => this.db.find({ type: 'movie' }, (error, docs) =>
resolve({ error, docs }),
resolve(docs.map(item => item.id)),
))

markEpisodeNotWatched = (showId: string, season: string, episode: string) =>
this.unmarkWatched({ showId, season, episode, type: 'episode' })

markEpisodeWatched = (showId: string, season: string, episode: string) =>
this.markWatched({ showId, season, episode, type: 'episode' })
markEpisodeWatched = (showId: string, season: string, episode: string, percentage: number) =>
this.markWatched({ showId, season, episode, percentage, type: 'episode' })

updateEpisodePercentage = (showId: string, season: string, episode: string, percentage: number) =>
new Promise(resolve =>
this.db.update({ showId, season, episode, type: 'episode' }, { $set: { percentage } }, {}, (err, numAffected) => {
if (!numAffected) {
this.markEpisodeWatched(showId, season, episode, percentage).then(resolve)

} else {
resolve()
}
}))

getEpisodesWatchedOfShow = (showId: string) =>
new Promise(resolve => this.db.find(
getEpisodesWatchedOfShow = (showId: string) => new Promise(resolve =>
this.db.find(
{
showId,
type: 'episode',
Expand Down
35 changes: 0 additions & 35 deletions app/api/Events.js

This file was deleted.

31 changes: 14 additions & 17 deletions app/api/Metadata/MetadataAdapter.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import Database from 'api/Database'
import { MetadataProviderInterface } from './MetadataProviderInterface'
import TraktMetadataProvider from './TraktMetadataProvider'
import TmdbMetadataProvider from './TmdbMetadataProvider'

export class MetadataAdapter implements MetadataProviderInterface {

providers = [
new TraktMetadataProvider(),
]
trakt: TraktMetadataProvider

getSeasons = (itemId: string, pctSeasons) => new Promise(resolve =>
Database.watched.getEpisodesWatchedOfShow(itemId).then(({ docs }) => Promise.all(
this.providers.map(provider => provider.getSeasons(itemId, pctSeasons, docs)),
).then((response) => {
const seasons = []
tmdb: TmdbMetadataProvider

response.forEach(providerSeasons => providerSeasons.forEach((season) => {
seasons.push({
...season,
})
}))
constructor() {
this.trakt = new TraktMetadataProvider()
this.tmdb = new TmdbMetadataProvider()
}

resolve(seasons)
}),
),
)
getSeasons = (itemId: string, pctSeasons) => new Promise((resolve) => {
Database.watched.getEpisodesWatchedOfShow(itemId).then(({ docs }) =>
this.trakt.getIds(itemId).then(({ ids: { tmdb } }) =>
this.tmdb.getSeasons(itemId, tmdb, pctSeasons, docs).then(resolve),
),
)
})

}

Expand Down
2 changes: 1 addition & 1 deletion app/api/Metadata/MetadataConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export const TYPE_SHOW_EPISODE = 'show.episode'

export const PLURALS = {
[TYPE_SHOW] : `${TYPE_SHOW}s`,
[TYPE_MOVIE]: `${TYPE_SHOW}s`,
[TYPE_MOVIE]: `${TYPE_MOVIE}s`,
}
2 changes: 1 addition & 1 deletion app/api/Metadata/MetadataProviderInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { MovieType, ShowType } from './MetadataTypes'

export interface MetadataProviderInterface {

getMovies: (page: number, limit: number, options: optionsType) => Promise<MovieType>,
getMovies: (page: number, limit: number, options: Object) => Promise<MovieType>,

getMovie: (itemId: string) => MovieType,

Expand Down
Loading

0 comments on commit a7169c5

Please sign in to comment.