Skip to content

Commit

Permalink
Boundary condition processing
Browse files Browse the repository at this point in the history
  • Loading branch information
fhyoga committed Sep 28, 2019
1 parent 93c7e13 commit 5adf4a4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
39 changes: 18 additions & 21 deletions app/components/MediaInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Row, Col, Tag, Select } from 'antd';
import cn from 'classnames';
import { get } from 'lodash';
import styles from './index.less';

const { Option } = Select;
Expand All @@ -17,39 +18,39 @@ export default ({
onSelect = () => {},
tags = []
}: Props) => {
const selectedTags =
(currentMediaInfo.tag && currentMediaInfo.tag.map(tag => tag._text)) || [];
const selectedTags = get(currentMediaInfo, 'tag', []).map(tag => tag._text);
return (
<Row>
<div className={styles.media_info}>
<div className={styles.media_title}>{currentMediaInfo.title._text}</div>
<div className={styles.media_title}>
{get(currentMediaInfo, 'title._text')}
</div>
<Col span={8} offset={2}>
<img
style={{ maxWidth: '100%' }}
src={currentMediaInfo.art && currentMediaInfo.art.poster._text}
src={get(currentMediaInfo, 'art.poster._text')}
alt=""
/>
</Col>
<Col span={12} offset={2}>
<div className={styles.info_item}>
<div className={styles.info_label}>ID:</div>
<div className={cn(styles.info_text, styles.uniqueid)}>
{currentMediaInfo.uniqueid._text}
{get(currentMediaInfo, 'uniqueid._text')}
</div>
</div>
<div className={styles.info_item}>
<div className={styles.info_label}>发行日期:</div>
<div className={cn(styles.info_text)}>
{currentMediaInfo.premiered._text}
{get(currentMediaInfo, 'premiered._text')}
</div>
</div>
<div className={styles.info_item}>
<div className={styles.info_label}>类型:</div>
<div className={cn(styles.info_text, styles.genre)}>
{currentMediaInfo.genre &&
currentMediaInfo.genre.map(g => (
<Tag key={g._text}>{g._text}</Tag>
))}
{get(currentMediaInfo, 'genre', []).map(g => (
<Tag key={g._text}>{g._text}</Tag>
))}
</div>
</div>
<div className={styles.info_item}>
Expand All @@ -69,23 +70,19 @@ export default ({
))}
</Select>
) : (
currentMediaInfo.tag &&
currentMediaInfo.tag.map(g => (
<Tag key={g._text}>{g._text}</Tag>
))
selectedTags.map(g => <Tag key={g._text}>{g._text}</Tag>)
)}
</div>
</div>
<div className={styles.info_item}>
<div className={styles.info_label}>演员:</div>
<div className={cn(styles.info_text, styles.actor)}>
{currentMediaInfo.actor &&
currentMediaInfo.actor.map(a => (
<figure key={a.name._text}>
<img src={a.thumb._text} alt="" />
<figcaption>{a.name._text}</figcaption>
</figure>
))}
{get(currentMediaInfo, 'actor', []).map(a => (
<figure key={a.name._text}>
<img src={a.thumb._text} alt="" />
<figcaption>{a.name._text}</figcaption>
</figure>
))}
</div>
</div>
</Col>
Expand Down
21 changes: 11 additions & 10 deletions app/containers/Home/MainContent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import path from 'path';
import { connect } from 'react-redux';
import MediaInfo from '@components/MediaInfo';
Expand All @@ -19,16 +19,17 @@ const tags = config.get('tags', []) as string[];
const MainContent = ({ selectedKey, flatTree }) => {
const [mediaInfo, setMediaInfo] = useState(null);
let nfoPath = '';
if (selectedKey) {
const node = flatTree[selectedKey];
nfoPath = path.join(node.wpath, `${node.title}.nfo`);
try {
setMediaInfo(readMediaInfoFromNFOSync(nfoPath));
} catch (error) {
console.info('no nfo file');
useEffect(() => {
if (selectedKey) {
const node = flatTree[selectedKey];
nfoPath = path.join(node.wpath, `${node.title}.nfo`);
try {
setMediaInfo(readMediaInfoFromNFOSync(nfoPath));
} catch (error) {
console.info('no nfo file');
}
}
console.log(mediaInfo);
}
}, [selectedKey]);
return mediaInfo ? (
<MediaInfo
currentMediaInfo={mediaInfo}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "u-scraper",
"productName": "uScraper",
"version": "0.1.0-beta",
"version": "0.1.0",
"description": "A scraper that switches between normal mode and gentleman mode, built on Eletron, React",
"scripts": {
"build": "concurrently \"yarn build-main\" \"yarn build-renderer\"",
Expand Down Expand Up @@ -274,6 +274,7 @@
"electron-updater": "^4.0.6",
"fs-extra": "^8.0.1",
"json2xml": "^0.1.3",
"lodash-es": "^4.17.15",
"puppeteer-core": "^1.20.0",
"ramda": "^0.26.1",
"react": "^16.7.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8727,7 +8727,7 @@ locate-path@^3.0.0:
p-locate "^3.0.0"
path-exists "^3.0.0"

lodash-es@^4.2.1:
lodash-es@^4.17.15, lodash-es@^4.2.1:
version "4.17.15"
resolved "https://registry.npm.taobao.org/lodash-es/download/lodash-es-4.17.15.tgz#21bd96839354412f23d7a10340e5eac6ee455d78"
integrity sha1-Ib2Wg5NUQS8j16EDQOXqxu5FXXg=
Expand Down

0 comments on commit 5adf4a4

Please sign in to comment.