Prechádzať zdrojové kódy

fix: launch/download error;
fix: missing download count in details page;
mod: show stat in grid list

HOME 3 rokov pred
rodič
commit
62554ebd9d

+ 2 - 2
src/actions/queueActions.js

@@ -89,7 +89,7 @@ export const downloadSong = (identity) => (dispatch, getState) => {
                 let zipEntries = zip.getEntries()
                 let infoEntry
                 for(let i = 0; i < zipEntries.length; i++) {
-                  if(zipEntries[i].entryName.split(path.sep).pop() === 'info.dat') {
+                  if(zipEntries[i].entryName.split(path.sep).pop().toLowerCase() === 'info.dat') {
                     infoEntry  = zipEntries[i]
                   }
                 }
@@ -287,7 +287,7 @@ export const downloadSong = (identity) => (dispatch, getState) => {
           let zipEntries = zip.getEntries()
           let infoEntry, infoObject
           for(let i = 0; i < zipEntries.length; i++) {
-            if(zipEntries[i].entryName.substr(zipEntries[i].entryName.length - 9, 9) === 'info.json' || zipEntries[i].entryName.substr(zipEntries[i].entryName.length - 8, 9) === 'info.dat') {
+            if(zipEntries[i].entryName.substr(zipEntries[i].entryName.length - 9, 9) === 'info.json' || zipEntries[i].entryName.substr(zipEntries[i].entryName.length - 8, 9).toLowerCase() === 'info.dat') {
               infoEntry = zipEntries[i]
             }
           }

+ 12 - 8
src/components/App.js

@@ -58,15 +58,19 @@ class App extends Component {
           for(let i = 0; i < message.mods.install.length; i++) {
             installMod(message.mods.install[i], '')(store.dispatch, store.getState)
           }
-          for(let i = 0; i < message.files.length; i++) {
-            let dir = message.files[i].file.split(path.sep)
-            let filename = dir[dir.length - 1] + message.files[i].ext
-            let newPath = path.join(store.getState().settings.installationDirectory, "Playlists", filename);
-            fs.rename(message.files[i].file, newPath, (err) => {
-              if (err) throw err;
-              fetchLocalPlaylists(true)(store.dispatch, store.getState)
-            })
+          
+          if(message.files){
+            for(let i = 0; i < message.files.length; i++) {
+              let dir = message.files[i].file.split(path.sep)
+              let filename = dir[dir.length - 1] + message.files[i].ext
+              let newPath = path.join(store.getState().settings.installationDirectory, "Playlists", filename);
+              fs.rename(message.files[i].file, newPath, (err) => {
+                if (err) throw err;
+                fetchLocalPlaylists(true)(store.dispatch, store.getState)
+              })
+            }
           }
+
           return
         default:
           return

+ 9 - 4
src/components/CoverGrid.js

@@ -79,10 +79,15 @@ class CoverGrid extends Component {
                   artist={ song.authorName || song._songAuthorName || (song.metadata === undefined ? null : song.metadata.songAuthorName) }
                   difficulties={ song.difficulties || song.difficultyLevels || song._difficultyBeatmapSets || song.metadata.difficulties }
                   imageSource={ song.coverURL || song.coverUrl }
-                  songKey={ song.key } hash={ song.hash || song.hashMd5 }
-                  file={ song.file } downloads={ song.downloadCount }
-                  upvotes={ song.upVotes } downvotes={ song.downVotes }
-                  plays={ song.playedCount }
+                  songKey={ song.key }
+                  hash={ song.hash || song.hashMd5 }
+                  file={ song.file }
+
+                  downloads={ song.stats ? song.stats.downloads : song.downloadCount }
+                  upvotes={ song.stats ? song.stats.upVotes : song.upVotes }
+                  downvotes={ song.stats ? song.stats.downVotes : song.downVotes }
+                  plays={ song.stats ? song.stats.plays : song.playedCount }
+                  uploadDate={ !!song.uploaded ? new Date(Date.parse(song.uploaded)).toLocaleString() : '' }
                 />
                 <ContextMenu id={ song.hash || song.hashMd5 }>
                   <MenuItem onClick={ (e) => {e.stopPropagation(); (!!song.file || this.props.songs.downloadedSongs.some(dsong => dsong.hash === (song.hash || song.hashMd5))) ? this.props.deleteSong(song.file || song.hash || song.hashMd5) : this.props.downloadSong(song.hash || song.hashMd5)} }>

+ 28 - 0
src/components/CoverGridItem.js

@@ -56,6 +56,28 @@ function Difficulties(props) {
   })
 }
 
+function VoteRatio(props){
+  var total = props.up + props.down;
+  if(props.up > props.down){
+    return <span>👍{(props.up / total * 100).toFixed(1) }/<CompactNumber value={ props.up + props.down }/></span>
+  }else if (props.up < props.down){
+    return <span>👎{(props.down / total * 100).toFixed(1)}/<CompactNumber value={ props.up + props.down }/></span>
+  }else{  
+    return <span></span>
+  }
+}
+
+function CompactNumber(props){
+  var num = props.value, uni = 0;  
+
+  if( num >= 100 && num < 1000) return <span>{(num / 100).toFixed(0)}H</span>
+  if( num >= 1000 && num < 10000) return <span>{(num / 1000).toFixed(0)}K</span>
+  if( num >= 10000 && num < 1000000) return <span>{(num / 10000).toFixed(0)}万</span>
+  if( num >= 1000000 && num < 10000000) return <span>{(num / 1000000).toFixed(0)}M</span>
+
+  return <span>{num}</span>
+}
+
 class CoverGridItem extends Component {
 
   constructor() {
@@ -98,6 +120,7 @@ componentWillReceiveProps(props) {
         </div>
       )
     } else {
+      //debugger here
       return (
         <div key={ this.props.key } className='cover-grid-item' onClick={ () => { this.props.setScrollTop(document.getElementById('cover-grid-container').scrollTop); if(this.props.file) { this.props.loadDetailsFromFile(this.props.file) } else { this.props.loadDetailsFromKey(this.props.songKey) } } }>
           <img className="cover-image" src={ this.props.imageSource.startsWith('file://') ? this.props.imageSource : `https://beatsaver.com${ this.props.imageSource }` } alt=""/>
@@ -105,6 +128,11 @@ componentWillReceiveProps(props) {
           <div style={ { backgroundColor: this.state.bgc, color: this.state.textColor } } className="cover-grid-info-tab">
             <div className="cover-grid-title">{this.props.title}</div>
             <div className="cover-grid-artist">{this.props.artist}</div>
+            <div>
+              {/* 👍{ this.props.upvotes } 👎{ this.props.downvotes } */}
+              <VoteRatio up={ this.props.upvotes } down={ this.props.downvotes } />
+              🏁{ ( 100 * this.props.plays / this.props.downloads).toFixed(1) }/<CompactNumber value={ this.props.downloads }/>
+            </div>
             <div className="dots">
               <Difficulties difficulties={ this.props.difficulties } textColor={ this.state.textColor } />
             </div>

+ 1 - 1
src/components/SongDetails.js

@@ -119,7 +119,7 @@ function BeatSaver(props) {
   return (
     <div className="details-ratings">
       <b>BeatSaver Details:</b>
-      <div className="details-downloads">&nbsp;&nbsp;&nbsp;&nbsp;<b><span role="img" aria-label="downloads">⏬</span> Downloads: </b>{props.details.stats.downloadCount}</div>
+      <div className="details-downloads">&nbsp;&nbsp;&nbsp;&nbsp;<b><span role="img" aria-label="downloads">⏬</span> Downloads: </b>{props.details.stats.downloads}</div>
       <div className="details-finishes">&nbsp;&nbsp;&nbsp;&nbsp;<b><span role="img" aria-label="finishes">🏁</span> Finishes: </b>{props.details.stats.plays}</div>
       <div className="details-updownvotes">&nbsp;&nbsp;&nbsp;&nbsp;<b><span role="img" aria-label="upvotes">👍</span>Upvotes: </b>{props.details.stats.upVotes}</div>
       <div className="details-updownvotes">&nbsp;&nbsp;&nbsp;&nbsp;<b><span role="img" aria-label="downvotes">👎</span> Downvotes: </b>{props.details.stats.downVotes}</div>

+ 1 - 0
src/components/SongList.js

@@ -85,6 +85,7 @@ class SongList extends Component {
                 tag: '.compact'
               }
             ];
+            //debugger here 1
             return (
               <ContextMenuTrigger id={ song.hash || song.hashMd5 }>
                 <SongListItem

+ 1 - 1
src/css/App.scss

@@ -8,7 +8,7 @@ body {
   overflow: hidden;
   background-color:#fff;
   cursor: default;
-  user-select: none;
+  // user-select: none;
   transition-duration: .2s;
   transition-property: background;
 }

+ 1 - 1
src/css/CoverGridItem.scss

@@ -22,7 +22,7 @@
   }
 
   .cover-grid-info-tab {
-    height: 76px;
+    height: 95px;
     width: 100%;
     background: rgb(128, 128, 128);
     margin-top: -4px;