Skip to content

Commit

Permalink
Tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
akameco committed Dec 12, 2016
1 parent 6a3fb25 commit 043a8fc
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/actions/addColumn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import type {Dispatch, Action} from '../types'
import Pixiv from '../util/pixiv'
import Pixiv from '../api/pixiv'
import type {Params, Endpoint} from '../types/column'
import type {User} from '../types/user'
import * as endpoint from '../constants/endpoint'
Expand Down
2 changes: 1 addition & 1 deletion app/actions/drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type {Action, Dispatch, State} from '../types'
import type {User, Profile} from '../types/user'
import type {DrawerType} from '../types/drawer'
import Pixiv, {normalizeIllusts} from '../util/pixiv'
import Pixiv, {normalizeIllusts} from '../api/pixiv'
import {getNextUrl} from '../reducers/drawer'
import {apiRequestSuccess} from './api'

Expand Down
2 changes: 1 addition & 1 deletion app/api/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import Pixiv, {normalizeIllusts, parseUrl} from '../util/pixiv'
import type {Endpoint, Params} from '../types/column'
import Pixiv, {normalizeIllusts, parseUrl} from './pixiv'

type FetchResponse = {
response: Object,
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion app/components/SearchField/SearchFiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, {Component} from 'react'
import {findDOMNode} from 'react-dom'
import throttle from 'lodash.throttle'
import Pixiv from '../../util/pixiv'
import Pixiv from '../../api/pixiv'
import PopoverAuto from './PopoverAuto'
import UsersOver from './UsersOver'
import styles from './SearchField.css'
Expand Down
17 changes: 7 additions & 10 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import React from 'react'
import {render} from 'react-dom'
import {Provider} from 'react-redux'
Expand All @@ -6,23 +7,19 @@ import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
import type {State} from './types'
import configureStore from './store'
import App from './components'
import Pixiv from './util/pixiv'
import Api from './api'
import './app.global.css'; // eslint-disable-line

injectTapEventPlugin()

async function init() {
const storage: State = localStorage.getItem('store')
let initialState: State = storage ? JSON.parse(storage) : {}
const storage: ?string = localStorage.getItem('store')
let initialState: $Shape<State> = storage ? JSON.parse(storage) : {}

const {auth, manage, columns} = initialState
const {auth, columns} = initialState

if (auth && manage) {
const {username, password} = auth
const {isLogin} = manage
if (username && password && isLogin) {
await Pixiv.login(username, password)
}
if (auth && auth.username && auth.password) {
await Api.login(auth.username, auth.password)
} else if (columns) {
initialState = {columns: initialState.columns}
}
Expand Down
11 changes: 7 additions & 4 deletions app/sagas/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ function * authorize(username: string, password: string): Generator<*, *, *> {

export function * autoLogin(): Generator<*, *, *> {
const {username, password} = yield select((state: State) => state.auth)
if (username && password) {
yield call(Api.login, username, password)
} else {
try {
if (username && password) {
yield call(Api.login, username, password)
return true
}
yield put(logout())
}
return false
} catch (err) { }
}

function * loginFlow(): Generator<*, *, *> {
Expand Down
33 changes: 27 additions & 6 deletions app/sagas/column.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import {fork, take, call, select, put} from 'redux-saga/effects'
import * as Actions from '../constants/column'
import * as endpoint from '../constants/endpoint'
import {getColumn} from '../reducers'
import type {Endpoint, Params} from '../types/column'
import {
Expand All @@ -23,24 +24,44 @@ export function * refreshAllColumns(): Generator<*, *, *> {
}

function * add(id: Id, endpoint: Endpoint, inputParams: Params): Generator<*, *, *> {
const {response, params} = yield call(Api.fetch, endpoint, inputParams)
yield put(apiRequestSuccess(response))
yield put(addColumnIllusts(id, response.result))
return {response, params}
try {
const {response, params} = yield call(Api.fetch, endpoint, inputParams)
yield put(apiRequestSuccess(response))
yield put(addColumnIllusts(id, response.result))
return {response, params}
} catch (err) {
console.error(err)
}
}

const checkEndpoint = (target: Endpoint) => target === endpoint.FOLLOW || target === endpoint.FOLLOW

function * checkUpdate(id: Id): Generator<*, *, *> {
yield call(autoLogin)
const state = yield select()
const column = getColumn(state, id)

if (checkEndpoint(column.endpoint)) {
const isLogin = yield call(autoLogin)
if (!isLogin) {
return false
}
}

const opts = {...column.params, ...resetParam}
yield call(add, id, column.endpoint, opts)
}

function * fetchColumn(id: Id) {
yield call(autoLogin)
const state = yield select()
const column = getColumn(state, id)

if (checkEndpoint(column.endpoint)) {
const isLogin = yield call(autoLogin)
if (!isLogin) {
return false
}
}

const {params} = yield call(add, id, column.endpoint, column.params)

if (params) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@
"style-loader": "^0.13.1",
"webpack": "^1.14.0",
"webpack-dev-server": "^1.16.2",
"webpack-merge": "^1.1.0"
"webpack-merge": "^1.1.1"
}
}
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5543,9 +5543,9 @@ webpack-dev-server@^1.16.2:
supports-color "^3.1.1"
webpack-dev-middleware "^1.4.0"

webpack-merge@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-1.1.0.tgz#e51d941c75f180219e73cc514cbf709f109ea26f"
webpack-merge@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-1.1.1.tgz#2816dce279f38fe05d62b6411144b7638553e61c"
dependencies:
lodash.clonedeep "^4.5.0"
lodash.differencewith "^4.5.0"
Expand Down

0 comments on commit 043a8fc

Please sign in to comment.