11import { GameOrderBy , GameOrderReverse } from 'flashpoint-launcher' ;
22import * as React from 'react' ;
33import { LangContext } from '../util/lang' ;
4+ import { useContext } from 'react' ;
45
56export type GameOrderProps = {
67 /** Called when the either the property to order by, or what way to order in, is changed. */
@@ -21,62 +22,59 @@ export type GameOrderChangeEvent = {
2122 * Two drop down lists, the first for selecting what to order the games by, and
2223 * the second for selecting what way to order the games in.
2324 */
24- export class GameOrder extends React . Component < GameOrderProps > {
25- render ( ) {
26- const strings = this . context . filter ;
27- const allStrings = this . context ;
28- return (
29- < >
30- { /* Order By */ }
31- < select
32- className = 'search-selector search-bar-order-dropdown'
33- value = { this . props . orderBy }
34- onChange = { this . onOrderByChange } >
35- < option value = 'title' > { strings . title } </ option >
36- < option value = 'developer' > { strings . developer } </ option >
37- < option value = 'publisher' > { strings . publisher } </ option >
38- < option value = 'series' > { strings . series } </ option >
39- < option value = 'platform' > { strings . platform } </ option >
40- < option value = 'releaseDate' > { allStrings . browse . releaseDate } </ option >
41- < option value = 'dateAdded' > { strings . dateAdded } </ option >
42- < option value = 'dateModified' > { strings . dateModified } </ option >
43- < option value = 'lastPlayed' > { allStrings . browse . lastPlayed } </ option >
44- < option value = 'playtime' > { allStrings . browse . playtime } </ option >
45- </ select >
46- { /* Order Reverse */ }
47- < select
48- className = 'search-selector search-bar-order-dropdown'
49- value = { this . props . orderReverse }
50- onChange = { this . onOrderReverseChange } >
51- < option value = 'ASC' > { strings . ascending } </ option >
52- < option value = 'DESC' > { strings . descending } </ option >
53- </ select >
54- </ >
55- ) ;
56- }
25+ export function GameOrder ( props : GameOrderProps ) {
26+ const allStrings = useContext ( LangContext ) ;
27+ const strings = allStrings . filter ;
5728
58- onOrderByChange = ( event : React . ChangeEvent < HTMLSelectElement > ) : void => {
59- this . updateOrder ( { orderBy : event . target . value as GameOrderBy } ) ; // Let the parser deal with invalid values instead. How would this even happen?
29+ const onOrderByChange = ( event : React . ChangeEvent < HTMLSelectElement > ) => {
30+ updateOrder ( { orderBy : event . target . value as GameOrderBy } ) ; // Let the parser deal with invalid values instead. How would this even happen?
6031 } ;
6132
62- onOrderReverseChange = ( event : React . ChangeEvent < HTMLSelectElement > ) : void => {
33+ const onOrderReverseChange = ( event : React . ChangeEvent < HTMLSelectElement > ) => {
6334 if ( isOrderReverse ( event . target . value ) ) {
64- this . updateOrder ( { orderReverse : event . target . value } ) ;
35+ updateOrder ( { orderReverse : event . target . value } ) ;
6536 } else {
6637 console . error ( `Failed to set "Order Reverse". Value is invalid! (value: "${ event . target . value } ")` ) ;
6738 }
6839 } ;
6940
70- updateOrder ( data : Partial < GameOrderChangeEvent > ) : void {
71- if ( this . props . onChange ) {
72- this . props . onChange ( {
73- orderBy : data . orderBy || this . props . orderBy ,
74- orderReverse : data . orderReverse || this . props . orderReverse ,
41+ const updateOrder = ( data : Partial < GameOrderChangeEvent > ) => {
42+ if ( props . onChange ) {
43+ props . onChange ( {
44+ orderBy : data . orderBy || props . orderBy ,
45+ orderReverse : data . orderReverse || props . orderReverse ,
7546 } ) ;
7647 }
77- }
48+ } ;
7849
79- static contextType = LangContext ;
50+ return (
51+ < >
52+ { /* Order By */ }
53+ < select
54+ className = 'search-selector search-bar-order-dropdown'
55+ value = { props . orderBy }
56+ onChange = { onOrderByChange } >
57+ < option value = 'title' > { strings . title } </ option >
58+ < option value = 'developer' > { strings . developer } </ option >
59+ < option value = 'publisher' > { strings . publisher } </ option >
60+ < option value = 'series' > { strings . series } </ option >
61+ < option value = 'platform' > { strings . platform } </ option >
62+ < option value = 'releaseDate' > { allStrings . browse . releaseDate } </ option >
63+ < option value = 'dateAdded' > { strings . dateAdded } </ option >
64+ < option value = 'dateModified' > { strings . dateModified } </ option >
65+ < option value = 'lastPlayed' > { allStrings . browse . lastPlayed } </ option >
66+ < option value = 'playtime' > { allStrings . browse . playtime } </ option >
67+ </ select >
68+ { /* Order Reverse */ }
69+ < select
70+ className = 'search-selector search-bar-order-dropdown'
71+ value = { props . orderReverse }
72+ onChange = { onOrderReverseChange } >
73+ < option value = 'ASC' > { strings . ascending } </ option >
74+ < option value = 'DESC' > { strings . descending } </ option >
75+ </ select >
76+ </ >
77+ ) ;
8078}
8179
8280function isOrderReverse ( value : string ) : value is GameOrderReverse {
0 commit comments