diff --git a/app/containers/Home/MainContent/index.tsx b/app/containers/Home/MainContent/index.tsx index f62c047..4b52c01 100644 --- a/app/containers/Home/MainContent/index.tsx +++ b/app/containers/Home/MainContent/index.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useRef } from 'react'; import path from 'path'; import { connect } from 'react-redux'; import MediaInfo from '@components/MediaInfo'; @@ -15,16 +15,16 @@ const mapStateToProps = ({ file }) => { flatTree }; }; -const tags = config.get('tags', []) as string[]; const MainContent = ({ selectedKey, flatTree }) => { const [mediaInfo, setMediaInfo] = useState(null); - let nfoPath = ''; + const nfoPath = useRef(''); + const tags = config.get('tags', []) as string[]; useEffect(() => { if (selectedKey) { const node = flatTree[selectedKey]; - nfoPath = path.join(node.wpath, `${node.title}.nfo`); + nfoPath.current = path.join(node.wpath, `${node.title}.nfo`); try { - setMediaInfo(readMediaInfoFromNFOSync(nfoPath)); + setMediaInfo(readMediaInfoFromNFOSync(nfoPath.current)); } catch (error) { console.info('no nfo file'); setMediaInfo(null); @@ -37,12 +37,13 @@ const MainContent = ({ selectedKey, flatTree }) => { tags={tags} onSelect={iTags => { config.set('tags', [...new Set(tags.concat(iTags))]); - if (!nfoPath) return; + console.log(nfoPath.current); + if (!nfoPath.current) return; const info = Object.assign({}, mediaInfo, { tag: iTags.map(tag => ({ _text: tag })) }); setMediaInfo({ ...mediaInfo, tag: iTags.map(tag => ({ _text: tag })) }); - writeMediaInfoToNFOSync(nfoPath, info); + writeMediaInfoToNFOSync(nfoPath.current, info); }} selectable /> diff --git a/package.json b/package.json index 0e02c29..4d2c1e6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "u-scraper", "productName": "uScraper", - "version": "0.2.0", + "version": "0.2.1", "description": "A scraper that switches between normal mode and gentleman mode, built on Eletron, React", "scripts": { "build": "concurrently \"yarn build-main\" \"yarn build-renderer\"",