Skip to content

Commit

Permalink
feat: trending tags
Browse files Browse the repository at this point in the history
  • Loading branch information
kokororin committed Apr 12, 2020
1 parent a991f1c commit b9a795c
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 169 deletions.
65 changes: 48 additions & 17 deletions src/actions/gallery.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Action, AnyAction } from 'redux';
import { ThunkAction, ThunkDispatch } from 'redux-thunk';
import namespacedTypes from 'namespaced-types';
import honoka from 'honoka';

import config from '@/config';
import * as api from '@/utils/api';
import { ICombinedState } from '@/reducers';

export interface IGalleryActionValues {
Expand All @@ -12,6 +10,8 @@ export interface IGalleryActionValues {
SET_PAGE: string;
SET_FETCH_ERROR: string;
SET_FETCH_STATUS: string;
SET_FETCH_TAGS_STATUS: string;
SET_TAGS: string;
SET_WORD: string;
CLEAR_SOURCE: string;
SET_ERROR_TIMES: string;
Expand All @@ -25,6 +25,8 @@ export const types = namespacedTypes('gallery', [
'SET_PAGE',
'SET_FETCH_ERROR',
'SET_FETCH_STATUS',
'SET_FETCH_TAGS_STATUS',
'SET_TAGS',
'SET_WORD',
'CLEAR_SOURCE',
'SET_ERROR_TIMES',
Expand Down Expand Up @@ -86,6 +88,24 @@ function setFetchStatus(isFetching: boolean) {
};
}

function setFetchTagsStatus(isFetching: boolean) {
return {
type: types.SET_FETCH_TAGS_STATUS,
payload: {
isFetching
}
};
}

export function setTags(data: any[]) {
return {
type: types.SET_TAGS,
payload: {
data
}
};
}

function setErrorTimes() {
return {
type: types.SET_ERROR_TIMES
Expand All @@ -103,12 +123,8 @@ function fetchSource(): TGalleryThunkAction {
dispatch(setFetchError(false));
dispatch(setFetchStatus(true));
if (getState().gallery.word === 'ranking') {
return honoka
.get(config.rankingURI, {
data: {
page: getState().gallery.page
}
})
return api
.ranking(getState().gallery.page)
.then(data => {
if (
data.status === 'success' &&
Expand All @@ -133,14 +149,10 @@ function fetchSource(): TGalleryThunkAction {
});
}

return honoka
.get(config.searchURI, {
mode: 'cors',
timeout: 30e3,
data: {
word: getState().gallery.word,
page: getState().gallery.page
}
return api
.search({
word: getState().gallery.word,
page: getState().gallery.page
})
.then(data => {
if (
Expand Down Expand Up @@ -175,6 +187,25 @@ export function fetchSourceIfNeeded(): TGalleryThunkAction {
};
}

export function fetchTags(): TGalleryThunkAction {
return dispatch => {
dispatch(setFetchTagsStatus(true));
return api
.tags()
.then(data => {
if (data.status === 'success' && data.response.tags) {
dispatch(setTags(data.response.tags));
}
})
.then(() => {
dispatch(setFetchTagsStatus(false));
})
.catch(() => {
dispatch(setFetchTagsStatus(false));
});
};
}

export function setWord(word: string) {
return {
type: types.SET_WORD,
Expand Down
16 changes: 6 additions & 10 deletions src/actions/illust.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Action } from 'redux';
import { ThunkAction, ThunkDispatch } from 'redux-thunk';
import namespacedTypes from 'namespaced-types';
import honoka from 'honoka';

import config from '@/config';
import * as api from '@/utils/api';
import getImagesFromZip from '@/utils/getImagesFromZip';
import { ICombinedState } from '@/reducers';

Expand Down Expand Up @@ -80,8 +78,8 @@ export function fetchItem(illustId: string): TIllustThunkAction {
return dispatch => {
dispatch(setFetchStatus(true));
dispatch(setFetchError(false));
return honoka
.get(`${config.illustURI}/${illustId}`)
return api
.illust(illustId)
.then(data => {
if (data.status === 'success') {
if (
Expand Down Expand Up @@ -165,11 +163,9 @@ export function fetchComments(illustId: string): TIllustThunkAction {
return (dispatch, getState) => {
dispatch(setFetchCommentsStatus(true));
dispatch(setFetchCommentsError(false));
return honoka
.get(`${config.commentsURI}/${illustId}`, {
data: {
page: getState().illust.page
}
return api
.illustComments(illustId, {
page: getState().illust.page
})
.then(data => {
if (data.status === 'success' && data.response.comments) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Img from 'react-image';
import EmojiParser from '@/utils/EmojiParser';
import getProxyImage from '@/utils/getProxyImage';
import * as api from '@/utils/api';

const useStyles = makeStyles({
listItem: {
Expand Down Expand Up @@ -90,7 +90,7 @@ const Comment: React.SFC<ICommentProps> = ({ item }) => {
<span className={classes.main}>
<div className={classes.avatar}>
<Img
src={[getProxyImage(item.user.profile_image_urls.medium)]}
src={[api.proxyImage(item.user.profile_image_urls.medium)]}
loader={
<img src="data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs=" />
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/ImageBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import isMobile from 'is-mobile';
import Hotkeys from 'react-hot-keys';
import { Chip } from '@material-ui/core';
import Loading from '@/components/Loading';
import getProxyImage from '@/utils/getProxyImage';
import * as api from '@/utils/api';

const useStyles = makeStyles({
root: {
Expand Down Expand Up @@ -132,7 +132,7 @@ const ImageBox: React.SFC<IImageBoxProps> = props => {
<div className={classes.root}>
<div className={classes.inner} onClick={props.onClose}>
<div className={classes.image}>
<Img src={getProxyImage(props.items[index])} loader={<Loading />} />
<Img src={api.proxyImage(props.items[index])} loader={<Loading />} />
</div>
</div>
{!isMobile() && (
Expand Down
4 changes: 2 additions & 2 deletions src/components/ImageItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { makeStyles } from '@material-ui/core/styles';
import { Link } from 'react-router-dom';
import Image from 'material-ui-image';
import StarIcon from '@material-ui/icons/Star';
import getProxyImage from '@/utils/getProxyImage';
import * as api from '@/utils/api';

const useStyles = makeStyles({
cell: {
Expand Down Expand Up @@ -122,7 +122,7 @@ const ImageItem: React.SFC<IImageItemProps> = props => {
<div className={classes.imageWrapper}>
<Image
aspectRatio={props.item.width / props.item.height}
src={getProxyImage(props.item.image_urls.medium)}
src={api.proxyImage(props.item.image_urls.medium)}
/>
</div>
<div className={classes.title}>
Expand Down
94 changes: 0 additions & 94 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,102 +7,8 @@ interface ILanguage {

export default {
apiBaseURL: 'https://api.kotori.love/pixiv',
galleryURI: '/gallery',
rankingURI: '/ranking',
searchURI: '/search',
illustURI: '/illust',
commentsURI: '/illust/comments',
authURI: '/user/auth',
favouriteURI: '/favourite',
baseURL: 'https://pixiv.moe/',
trackingID: 'UA-70944432-2',
projectLink: 'https://github.com/LoveLiveSunshine/pixiv.moe',
siteTitle: 'pixivギャラリー',
keywords: [
{
en: 'ranking',
jp: 'ランキング'
},
{
en: 'lovelive',
jp: 'ラブライブ'
},
{
en: 'honoka',
jp: '高坂穂乃果'
},
{
en: 'kotori',
jp: '南ことり'
},
{
en: 'umi',
jp: '園田海未'
},
{
en: 'maki',
jp: '西木野真姫'
},
{
en: 'rin',
jp: '星空凛'
},
{
en: 'hanayo',
jp: '小泉花陽'
},
{
en: 'nico',
jp: '矢澤にこ'
},
{
en: 'eli',
jp: '絢瀬絵里'
},
{
en: 'nozomi',
jp: '东条希'
},
{
en: 'sunshine',
jp: 'ラブライブ!サンシャイン!!'
},
{
en: 'chika',
jp: '高海千歌'
},
{
en: 'you',
jp: '渡辺曜'
},
{
en: 'riko',
jp: '桜内梨子'
},
{
en: 'yoshiko',
jp: '津島善子'
},
{
en: 'hanamaru',
jp: '国木田花丸'
},
{
en: 'dia',
jp: '黒澤ダイヤ'
},
{
en: 'ruby',
jp: '黒澤ルビィ'
},
{
en: 'mari',
jp: '小原鞠莉'
},
{
en: 'kanan',
jp: '松浦果南'
}
],
languages: [] as ILanguage[]
};
5 changes: 0 additions & 5 deletions src/containers/AppContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import blue from '@material-ui/core/colors/blue';
import red from '@material-ui/core/colors/red';
import { create } from 'jss';

import honoka from 'honoka';
import moment from 'moment';
import 'moment/locale/ja';

Expand All @@ -22,8 +21,6 @@ import Baseline from '@/components/Baseline';
import ScrollContext from '@/components/ScrollContext';
import TrackPageView from '@/components/TrackPageView';

import config from '@/config';

const theme = createMuiTheme({
palette: {
primary: { main: blue[500] },
Expand All @@ -36,8 +33,6 @@ const generateClassName = createGenerateClassName({
productionPrefix: 'p'
});

honoka.defaults.baseURL = config.apiBaseURL;
honoka.defaults.timeout = 30e3;
moment.locale('ja');

const routes = [
Expand Down

0 comments on commit b9a795c

Please sign in to comment.