Skip to content

Commit

Permalink
fix(tag):Tag error when switching files
Browse files Browse the repository at this point in the history
  • Loading branch information
fhyoga committed Sep 28, 2019
1 parent 7356b20 commit 93c7e13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions app/components/MediaInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default ({
onSelect = () => {},
tags = []
}: Props) => {
const defaultTags =
const selectedTags =
(currentMediaInfo.tag && currentMediaInfo.tag.map(tag => tag._text)) || [];
return (
<Row>
Expand Down Expand Up @@ -61,7 +61,8 @@ export default ({
style={{ width: '100%' }}
placeholder="选择标签"
onChange={onSelect}
defaultValue={defaultTags}
defaultValue={selectedTags}
value={selectedTags}
>
{tags.map(t => (
<Option key={t}>{t}</Option>
Expand Down
7 changes: 4 additions & 3 deletions app/containers/Home/MainContent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import path from 'path';
import { connect } from 'react-redux';
import MediaInfo from '@components/MediaInfo';
Expand All @@ -17,13 +17,13 @@ const mapStateToProps = ({ file }) => {
};
const tags = config.get('tags', []) as string[];
const MainContent = ({ selectedKey, flatTree }) => {
let mediaInfo = null;
const [mediaInfo, setMediaInfo] = useState(null);
let nfoPath = '';
if (selectedKey) {
const node = flatTree[selectedKey];
nfoPath = path.join(node.wpath, `${node.title}.nfo`);
try {
mediaInfo = readMediaInfoFromNFOSync(nfoPath);
setMediaInfo(readMediaInfoFromNFOSync(nfoPath));
} catch (error) {
console.info('no nfo file');
}
Expand All @@ -39,6 +39,7 @@ const MainContent = ({ selectedKey, flatTree }) => {
const info = Object.assign({}, mediaInfo, {
tag: iTags.map(tag => ({ _text: tag }))
});
setMediaInfo({ ...mediaInfo, tag: iTags.map(tag => ({ _text: tag })) });
writeMediaInfoToNFOSync(nfoPath, info);
}}
selectable
Expand Down

0 comments on commit 93c7e13

Please sign in to comment.