Skip to content

Commit

Permalink
fixed some setlist ui issues (#3)
Browse files Browse the repository at this point in the history
* remove travis.ci
* fixed a few UI bugs relating to the setlist
  • Loading branch information
theamazingfedex authored Oct 6, 2022
1 parent 31dbce8 commit ec26679
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 31 deletions.
81 changes: 60 additions & 21 deletions src/SongCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,68 @@ import { useDrag } from 'react-dnd';
import { GameTracks } from './constants';


export default function SongCard({setSongs, songInfo, warningToast}) {
export default function SongCard({allSongs, setAvailableSongs, setInstalledSongs, songInfo, warningToast}) {
// console.log('song card with info: ', songInfo)
const installItem = (currentItem, isInstalled) => {
setSongs((prevState) => {
// console.log('prevState: ', prevState);
// let tempState = prevState;
const installItem = (currentItem, shouldInstall) => {
if (shouldInstall) {
let didInstall = false;
setInstalledSongs(prevSongs => {
const tempSongs = prevSongs.filter(song => song.MainMusic.Event !== currentItem.name && song.BossMusic.Event !== currentItem.name);
const currentSong = allSongs.find(song => song.MainMusic.Event === currentItem.name && song.BossMusic.Event === currentItem.name);
if (!!currentSong) {
tempSongs.push(currentSong);
didInstall = true;
}
return tempSongs
// if some already installed song
// return [...prevSongs, ]
// return prevSongs.map(prevSong => {

if (!isInstalled && prevState.some(prevSong => {
return false;
return !prevSong.isInstalled && (prevSong.MainMusic.Event === currentItem.name && prevSong.BossMusic.Event === currentItem.name);
})) {
return prevState;
// return prevState.filter(pSong => !(!pSong.isInstalled && (pSong.MainMusic.Event === currentItem.name && pSong.BossMusic.Event === currentItem.name)));
} else {
return prevState.map(e => {
return {
...e,
// TODO: this is why the first load of setlist is funky sometimes, because this only gets set later, not at initial load:
// isInstalled: (e.MainMusic.Event === currentItem.name && e.LevelName === currentItem.type) ? isInstalled : e.isInstalled,
isInstalled: (isInstalled ? (e.MainMusic.Event === currentItem.name && e.LevelName === currentItem.type) : e.randomID === currentItem.randomID) ? isInstalled : e.isInstalled,
}
});
// });
// if(!prevSong.isInstalled && (prevSong.MainMusic.Event === currentItem.name && prevSong.BossMusic.Event === currentItem.name);
});
if (didInstall) {
setAvailableSongs(prevSongs => prevSongs.filter(prevSong => prevSong.MainMusic.Event !== currentItem.name && prevSong.BossMusic.Event !== currentItem.name));
// console.log('setting available songs to filter out currentItem.type: ', currentItem.type);
}
} else {
// should uninstall
let didUninstall = false;
setAvailableSongs(prevSongs => {
const tempSongs = prevSongs.filter(song => song.MainMusic.Event !== currentItem.name && song.BossMusic.Event !== currentItem.name);
const currentSong = allSongs.find(song => song.MainMusic.Event === currentItem.name && song.BossMusic.Event === currentItem.name);
if (!!currentSong) {
tempSongs.push(currentSong);
didUninstall = true;
}
return tempSongs
});
if (didUninstall) {
setInstalledSongs(prevSongs => prevSongs.filter(prevSong => prevSong.MainMusic.Event !== currentItem.name && prevSong.BossMusic.Event !== currentItem.name));
}

}

// setSongs((prevState) => {
// // console.log('prevState: ', prevState);
// // let tempState = prevState;

// if (!isInstalled && prevState.some(prevSong => {
// return false;
// return !prevSong.isInstalled && (prevSong.MainMusic.Event === currentItem.name && prevSong.BossMusic.Event === currentItem.name);
// })) {
// return prevState;
// // return prevState.filter(pSong => !(!pSong.isInstalled && (pSong.MainMusic.Event === currentItem.name && pSong.BossMusic.Event === currentItem.name)));
// } else {
// return prevState.map(e => {
// return {
// ...e,
// // TODO: this is why the first load of setlist is funky sometimes, because this only gets set later, not at initial load:
// // isInstalled: (e.MainMusic.Event === currentItem.name && e.LevelName === currentItem.type) ? isInstalled : e.isInstalled,
// isInstalled: (isInstalled ? (e.MainMusic.Event === currentItem.name && e.LevelName === currentItem.type) : e.randomID === currentItem.randomID) ? isInstalled : e.isInstalled,
// }
// });
// }
// .filter((e) => {
// if (!tempState.includes(s => s.MainMusic.Event === e.MainMusic.Event || s.BossMusic.Event === e.BossMusic.Event)) {
// tempState.push(e);
Expand All @@ -45,7 +84,7 @@ export default function SongCard({setSongs, songInfo, warningToast}) {
// // return acc
// });
// console.log('!?! new state: ', newState);
});
// });
}
const [{ isDragging }, dragRef] = useDrag(
() => ({
Expand Down
27 changes: 17 additions & 10 deletions src/SongManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export default function SongManager({ mods, setlist, setLastSavedSetlist, curGam
// } else {
// }
// console.log('allSongs: ', allSongs)
const [songs, setSongs] = useState([]);
const [installedSongs, setInstalledSongs] = useState([]);
const [availableSongs, setAvailableSongs] = useState([]);
const [songs, setSongs] = useState(setlist.concat(mods));
const [installedSongs, setInstalledSongs] = useState(setlist);
const [availableSongs, setAvailableSongs] = useState(mods);
const [searchTerm, setSearchTerm] = useState('');

let songSearcher = useMemo(() => new Searcher(availableSongs || [], { keySelector: (obj) => `${get(obj, 'LevelName')}${get(obj, 'MainMusic.Bank')}`}), [availableSongs])
Expand All @@ -41,18 +41,25 @@ export default function SongManager({ mods, setlist, setLastSavedSetlist, curGam
setInstalledSongs(allSongs && allSongs.filter(s => s.isInstalled) || [])
}, [mods, setlist]);

useEffect(() => {
setAvailableSongs(songs && songs.filter(s => !s.isInstalled) || [])
setInstalledSongs(songs && songs.filter(s => s.isInstalled) || [])
}, [songs]);
// useEffect(() => {

// setAvailableSongs(songs && songs.filter(s => !s.isInstalled) || [])
// setInstalledSongs(songs && songs.filter(s => s.isInstalled) || [])
// // setSongs(installedSongs.concat(availableSongs));
// }, [songs]);

useEffect(() => {
setLastSavedSetlist(installedSongs);
}, [installedSongs])

const clearSetlist = useCallback(() => {
setSongs(songs.map(s => ({ ...s, isInstalled: false })))
}, [songs]);
setAvailableSongs(prevSongs => {
const tempSongs = prevSongs.filter(song => !installedSongs.some(iSong => song.MainMusic.Event === iSong.MainMusic.Event && song.BossMusic.Event === iSong.BossMusic.Event));
return tempSongs.concat(installedSongs);
});
setInstalledSongs([]);
}, [songs, installedSongs]);

const returnItemsForSetlist =
// debounce(
Expand All @@ -64,10 +71,10 @@ export default function SongManager({ mods, setlist, setLastSavedSetlist, curGam
!!searchTerm && searchTerm.length > 0 ? searchResult : availableSongs;

return songsToMap.map(item => (
<SongCard key={item.LevelName + '-' + item.MainMusic.Event + '-' + item.randomID} songInfo={item} setSongs={setSongs} warningToast={warningToast}/>
<SongCard key={item.LevelName + '-' + item.MainMusic.Event + '-' + item.randomID} songInfo={item} allSongs={songs} setInstalledSongs={setInstalledSongs} setAvailableSongs={setAvailableSongs} warningToast={warningToast}/>
));
}
, [searchTerm, JSON.stringify(availableSongs)]);
, [searchTerm, JSON.stringify(availableSongs), JSON.stringify(songs)]);
// , 150);

const handleSearchInput = useCallback((e) => {
Expand Down

0 comments on commit ec26679

Please sign in to comment.