mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 18:17:38 +00:00
Sort by favorites on twitter
This commit is contained in:
parent
6eb5d062e4
commit
9d470c4368
3 changed files with 27 additions and 2 deletions
|
|
@ -29,6 +29,19 @@ const getFileNames = async () => {
|
|||
});
|
||||
return fileNames;
|
||||
};
|
||||
|
||||
const getFavoriteCounts = () => {
|
||||
const content = fs.readFileSync(path.join(__dirname, "../likes.txt"), "utf8");
|
||||
const favorites = {};
|
||||
content.split("\n").forEach(line => {
|
||||
if (!line.length) {
|
||||
return;
|
||||
}
|
||||
const [hash, fileName] = line.split(" ");
|
||||
favorites[hash] = fileName;
|
||||
});
|
||||
return favorites;
|
||||
};
|
||||
const testFolder = path.join(
|
||||
__dirname,
|
||||
"../../webamp/experiments/automatedScreenshots/screenshots/"
|
||||
|
|
@ -53,6 +66,8 @@ const genAverage = img => {
|
|||
|
||||
const getFileData = async files => {
|
||||
const fileNames = await getFileNames();
|
||||
const favortes = getFavoriteCounts();
|
||||
console.log(favortes);
|
||||
const fileData = {};
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i];
|
||||
|
|
@ -66,6 +81,7 @@ const getFileData = async files => {
|
|||
// Processes
|
||||
fileData[md5] = {
|
||||
color: (await genAverage(file)).slice(1),
|
||||
favorites: favortes[md5],
|
||||
fileName
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,16 @@ export function getMatchingHashes(state) {
|
|||
|
||||
export const getSkinHashes = createSelector(
|
||||
getSkins,
|
||||
skins => Object.keys(skins)
|
||||
skins => {
|
||||
const hashes = Object.keys(skins);
|
||||
hashes.sort((a, b) => {
|
||||
const aFaves = skins[a].favorites;
|
||||
const bFaves = skins[b].favorites;
|
||||
const res = (bFaves || 0) - (aFaves || 0);
|
||||
return res;
|
||||
});
|
||||
return hashes;
|
||||
}
|
||||
);
|
||||
|
||||
export const getMatchingSkinHashes = createSelector(
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue