Skip to content

Support likes fields #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const sortAxisOptions = [
"-commentCounter",
"+mylistCounter",
"-mylistCounter",
"+likeCounter",
"-likeCounter",
"+lengthSeconds",
"-lengthSeconds",
"+lastCommentTime",
Expand Down Expand Up @@ -260,6 +262,39 @@ const SearchBar: FC = () => {
<span className={styles.filterWord}>{t("common:max")}</span>
</label>
</div>
<div className={styles.filter}>
<span className={styles.filterName}>{t("like-count")}</span>
<label>
<input
className={styles.inputNumber}
type="number"
min="0"
value={options.likeCounterGte || ""}
onChange={(e) => {
searchDispatch({
type: "update",
payload: { likeCounterGte: parseInt(e.target.value) },
});
}}
/>
<span className={styles.filterWord}>{t("common:min")}</span>
</label>
<label>
<input
className={styles.inputNumber}
type="number"
min="0"
value={options.likeCounterLte || ""}
onChange={(e) => {
searchDispatch({
type: "update",
payload: { likeCounterLte: parseInt(e.target.value) },
});
}}
/>
<span className={styles.filterWord}>{t("common:max")}</span>
</label>
</div>
<div className={styles.filter}>
<span className={styles.filterName}>{t("date-filter")}</span>
<label className={styles.filterDate}>
Expand Down
3 changes: 3 additions & 0 deletions locales/en/SearchBar.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
"-commentCounter": "Least Comments",
"+mylistCounter": "Least My Listed",
"-mylistCounter": "Most My Listed",
"+likeCounter": "Least Liked",
"-likeCounter": "Most Liked",
"+lengthSeconds": "Shortest Duration",
"-lengthSeconds": "Longest Duration",
"+lastCommentTime": "Oldest Comments",
"-lastCommentTime": "Newest Comments",
"my-list-count": "# of My Lists",
"duration": "Duration (in minutes)",
"like-count": "Likes",
"duration-minutes-min": "min. length",
"duration-minutes-max": "max. length",
"views": "Views",
Expand Down
3 changes: 3 additions & 0 deletions locales/ja/SearchBar.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
"-commentCounter": "コメント数が多い順",
"+mylistCounter": "マイリスト数が少ない順",
"-mylistCounter": "マイリスト数が多い順",
"+likeCounter": "いいね数が少ない順",
"-likeCounter": "いいね数が多い順",
"+lengthSeconds": "再生時間が短い順",
"-lengthSeconds": "再生時間が長い順",
"+lastCommentTime": "コメントが古い順",
"-lastCommentTime": "コメントが新しい順",
"my-list-count": "マイリスト数",
"duration": "再生時間",
"like-count": "いいね数",
"duration-minutes-min": "分以上",
"duration-minutes-max": "分以下",
"views": "再生数",
Expand Down
17 changes: 17 additions & 0 deletions pages_/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ const getSearchQuery = ({
mylistCounterLte,
viewCounterGte,
viewCounterLte,
likeCounterGte,
likeCounterLte,
lengthMinutesGte,
lengthMinutesLte,
startTimeGte,
Expand Down Expand Up @@ -166,6 +168,19 @@ const getSearchQuery = ({
filters["viewCounter"]["lte"] = viewCounterLte;
}

if (likeCounterGte) {
if (!filters["likeCounter"]) {
filters["likeCounter"] = {};
}
filters["likeCounter"]["gte"] = likeCounterGte;
}
if (likeCounterLte !== null) {
if (!filters["likeCounter"]) {
filters["likeCounter"] = {};
}
filters["likeCounter"]["lte"] = likeCounterLte;
}

if (startTimeGte) {
if (!filters["startTime"]) {
filters["startTime"] = {};
Expand Down Expand Up @@ -288,6 +303,8 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
mylistCounterLte: roundNumber(parseQueryToInt(query.mylistCounterLte)),
viewCounterGte: roundNumber(parseQueryToInt(query.viewCounterGte)),
viewCounterLte: roundNumber(parseQueryToInt(query.viewCounterLte)),
likeCounterGte: roundNumber(parseQueryToInt(query.likeCounterGte)),
likeCounterLte: roundNumber(parseQueryToInt(query.likeCounterLte)),
lengthMinutesGte: roundNumber(
parseQueryToLimitedFloat(query.lengthMinutesGte)
),
Expand Down
2 changes: 2 additions & 0 deletions reducers/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type SearchOptions = {
lengthMinutesLte?: number;
viewCounterGte?: number;
viewCounterLte?: number;
likeCounterGte?: number;
likeCounterLte?: number;
userId?: number;
count?: number;
page?: number;
Expand Down