Skip to content

Commit

Permalink
✨ Replace yahoo sorting with line sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Sing Ming Chen committed Nov 15, 2023
1 parent 8b85190 commit 09d25df
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/app/components/appBarNormal.tsx
Expand Up @@ -92,10 +92,10 @@ class AppBarNormal extends React.PureComponent<any, any> {
}}
/>
<MenuItem
primaryText="依Yahoo排序"
primaryText="依LINE Movie排序"
onTouchTap={(e) => {
e.preventDefault();
this.props.switchSorting(SortType.yahoo);
this.props.switchSorting(SortType.line);
}}
/>
<MenuItem
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/theaterDetail.tsx
Expand Up @@ -86,7 +86,7 @@ class TheaterDetail extends React.PureComponent<any, { selectedIndex: number }>
return <LoadingIcon isLoading={loading} />;
}
const theater: Theater = theaters[0];
document.title = `${theater.name}時刻表 | 按iMDb/LINE/PTT評分排序`;
document.title = `${theater.name}時刻表 | 按IMDb/LINE/PTT評分排序`;
document['meta'] = {
description: generateTheaterDescription(theater),
};
Expand Down
46 changes: 23 additions & 23 deletions src/app/sorting.ts
Expand Up @@ -2,33 +2,33 @@ import Movie from '../models/movie';
import * as moment from 'moment';

enum SortType {
imdb = 0,
yahoo = 1,
ptt = 2,
releaseDate = 3
imdb = 0,
line = 1,
ptt = 2,
releaseDate = 3,
}

let preSortType;
let preOrder = 1;
const getSortFunction = (sortType) => {
let order = sortType === preSortType ? preOrder * -1 : 1;
preOrder = order;
preSortType = sortType;
let sortFunction = (a, b) => (getValue(b, sortType) - getValue(a, sortType)) * order;
return sortFunction;
}
let order = sortType === preSortType ? preOrder * -1 : 1;
preOrder = order;
preSortType = sortType;
let sortFunction = (a, b) => (getValue(b, sortType) - getValue(a, sortType)) * order;
return sortFunction;
};

const getValue = (movie, sortType) => {
switch (sortType) {
case SortType.imdb:
return movie.imdbRating === 'N/A' ? 0 : movie.imdbRating;
case SortType.ptt:
return movie.goodRateArticles.length - movie.badRateArticles.length
case SortType.yahoo:
return movie.yahooRating === 'N/A' ? 0 : movie.yahooRating;
case SortType.releaseDate:
return moment(movie.releaseDate)
}
}
const getValue = (movie: Movie, sortType) => {
switch (sortType) {
case SortType.imdb:
return !movie.imdbRating || movie.imdbRating === 'N/A' ? 0 : parseFloat(movie.imdbRating);
case SortType.ptt:
return movie.goodRateArticles.length - movie.badRateArticles.length;
case SortType.line:
return !movie.lineRating || movie.lineRating === 'N/A' ? 0 : parseFloat(movie.lineRating);
case SortType.releaseDate:
return moment(movie.releaseDate).valueOf();
}
};

export { getSortFunction, SortType }
export { getSortFunction, SortType };

0 comments on commit 09d25df

Please sign in to comment.