-
-
Notifications
You must be signed in to change notification settings - Fork 67
Refactor state mgmt #1326
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
Draft
HerveH44
wants to merge
14
commits into
master
Choose a base branch
from
refactor-state-mgmt
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Refactor state mgmt #1326
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
99e178f
connect StartPanel simple buttons to redux store
HerveH44 d8ec068
add timerLength
HerveH44 8d7f9b5
connect start event with redux store
HerveH44 6734394
introduce persistance capability
HerveH44 46964b6
rename startControls
HerveH44 c28c2c5
delete start controls from app state
HerveH44 0daa051
delete console logs
HerveH44 e96c414
reformat doc
HerveH44 083d8ba
solve spaces pb
HerveH44 88d46da
fix eslint problems
HerveH44 c7a34b0
more eslint pb
HerveH44 8345a80
use gameSettings redux store
4befaf5
Merge branch 'master' into refactor-state-mgmt
2234a97
follow mixmix recommandations
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,132 +1,172 @@ | ||
| import { capitalize } from "lodash"; | ||
| import React from "react"; | ||
| import { useDispatch, useSelector } from "react-redux"; | ||
|
|
||
| import App from "../app"; | ||
| import Checkbox from "../components/Checkbox"; | ||
| import './GameSettings.scss'; | ||
| import { imgLanguageDisplay, selectBeep, selectCardLang, setNotificationResult, changeSort, toggleCols, selectCardSize, selectChat, selectHidepicks, notificationBlocked, selectNotify, selectSort, toggleChat, toggleNotify, toggleBeep, selectSide, toggleSide, toggleHidepicks, selectCols, sortChoices, sizeDisplay, changeCardSize, changeCardLang } from "../state/game-settings"; | ||
| import "./GameSettings.scss"; | ||
|
|
||
| const GameSettings = () => ( | ||
| <div className='Game-Settings'> | ||
| <fieldset className='fieldset'> | ||
| <legend className='legend game-legend'>Settings</legend> | ||
| <span> | ||
| <Checkbox side="left" text="Show chat" link="chat" /> | ||
| {!App.state.isSealed && | ||
| <Checkbox side="left" text="Enable notifications on new packs" link="beep" /> | ||
| const GameSettings = () => { | ||
| const dispatch = useDispatch(); | ||
| const beep = useSelector(selectBeep); | ||
| const notify = useSelector(selectNotify); | ||
| const isNotificationBlocked = useSelector(notificationBlocked); | ||
| const chat = useSelector(selectChat); | ||
| const side = useSelector(selectSide); | ||
| const hidePicks = useSelector(selectHidepicks); | ||
| const cols = useSelector(selectCols); | ||
|
|
||
| //TODO: that could go inside the reducer? But it has an async behavior ... | ||
| const onNotificationChange = () => { | ||
| if (!notify) { | ||
| dispatch(toggleNotify()); | ||
| } else if ("Notification" in window) { | ||
| Notification.requestPermission().then((result) => { | ||
| dispatch(setNotificationResult(result)); | ||
| if (result === "granted") { | ||
| dispatch(toggleNotify()); | ||
| } | ||
| {!App.state.isSealed && | ||
| }); | ||
| } else { | ||
| dispatch(setNotificationResult("notsupported")); | ||
| if (notify) { | ||
| dispatch(toggleNotify()); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className='Game-Settings'> | ||
| <fieldset className='fieldset'> | ||
| <legend className='legend game-legend'>Settings</legend> | ||
| <span> | ||
| <Checkbox | ||
| side="left" | ||
| text="Show chat" | ||
| value={chat} | ||
| onChange={() => dispatch(toggleChat())} /> | ||
| {!App.state.isSealed && | ||
| <Checkbox | ||
| side="left" | ||
| text="Enable notifications on new packs" | ||
| value={beep} | ||
| onChange={() => dispatch(toggleBeep())} /> | ||
| } | ||
| {!App.state.isSealed && | ||
| <div style={{paddingLeft: "10px"}} > | ||
| <Checkbox side="left" | ||
| text={App.state.notificationBlocked ? "Web notifications blocked in browser" : "Use desktop notifications over beep"} | ||
| link="notify" | ||
| disabled={!App.state.beep || App.state.notificationBlocked} | ||
| onChange={App._emit("notification")} /> | ||
| text={isNotificationBlocked ? "Web notifications blocked in browser" : "Use desktop notifications over beep"} | ||
| value={notify} | ||
| disabled={!beep || isNotificationBlocked} | ||
| onChange={onNotificationChange} /> | ||
| </div> | ||
| } | ||
| {!App.state.isSealed && | ||
| <Checkbox side="left" text="Add picks to sideboard" link="side" />} | ||
| {!App.state.isSealed && | ||
| <Checkbox side="left" text="Hide your picks" link="hidepicks" /> | ||
| } | ||
| <Checkbox side="left" text="Use column view" link="cols" /> | ||
| <SortCards /> | ||
| <CardsImageQuality /> | ||
| {App.state.cardSize != "text" && <CardsImageLanguage />} | ||
| </span> | ||
| </fieldset> | ||
| </div> | ||
| ); | ||
| } | ||
| {!App.state.isSealed && | ||
| <Checkbox | ||
| side="left" | ||
| text="Add picks to sideboard" | ||
| value={side} | ||
| onChange={() => dispatch(toggleSide())} />} | ||
| {!App.state.isSealed && | ||
| <Checkbox | ||
| side="left" | ||
| text="Hide your picks" | ||
| value={hidePicks} | ||
| onChange={() => dispatch(toggleHidepicks())} />} | ||
| <Checkbox | ||
| side="left" | ||
| text="Use column view" | ||
| value={cols} | ||
| onChange={() => dispatch(toggleCols())} /> | ||
| <SortCards /> | ||
| <CardsImageQuality /> | ||
| {App.state.cardSize != "text" && <CardsImageLanguage />} | ||
| </span> | ||
| </fieldset> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const SortCards = () => ( | ||
| <div className="sort-cards"> | ||
| Sort cards by: | ||
| <div className='connected-container' > | ||
| {["CMC", "Color", "Type", "Rarity"].map((sort, index) => { | ||
| const isActive = sort.toLowerCase() === App.state.sort | ||
| const SortCards = () => { | ||
| const dispatch = useDispatch(); | ||
| const sortValue = useSelector(selectSort); | ||
| return ( | ||
| <div className="sort-cards"> | ||
| Sort cards by: | ||
| <div className='connected-container' > | ||
| {sortChoices.map((sort, index) => { | ||
| const isActive = sort === sortValue; | ||
|
|
||
| return ( | ||
| <label key={index} | ||
| className={isActive | ||
| ? "active connected-component" | ||
| : "connected-component" | ||
| } | ||
| > | ||
| <input checked= {isActive} | ||
| className='radio-input' | ||
| name= 'sort-order' | ||
| onChange= {e => App.save("sort", e.currentTarget.value)} | ||
| type='radio' | ||
| value={sort.toLowerCase()} | ||
| /> | ||
| <div>{sort}</div> | ||
| </label> | ||
| ) | ||
| })} | ||
| return ( | ||
| <label | ||
| key={index} | ||
| className={isActive ? "active connected-component" : "connected-component"}> | ||
| <input checked= {isActive} | ||
| className='radio-input' | ||
| name= 'sort-order' | ||
| onChange= {e => dispatch(changeSort(e.currentTarget.value))} | ||
| type='radio' | ||
| value={sort} | ||
| /> | ||
| <div>{capitalize(sort)}</div> | ||
| </label> | ||
| ); | ||
| })} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
|
|
||
| const sizeDisplay = { | ||
| "text": "Text-Only", | ||
| "small": "Low", | ||
| "normal": "Medium", | ||
| "large": "High", | ||
| }; | ||
| );}; | ||
|
|
||
| const CardsImageQuality = () => ( | ||
| <div className="card-quality"> | ||
| const CardsImageQuality = () => { | ||
| const dispatch = useDispatch(); | ||
| const cardSize = useSelector(selectCardSize); | ||
| const cardLang = useSelector(selectCardLang); | ||
| return ( | ||
| <div className="card-quality"> | ||
| Card image quality: | ||
| <div className='connected-container'> | ||
| {Object.keys(sizeDisplay).map((size, index) => { | ||
| const isActive = size.toLowerCase() === App.state.cardSize | ||
| <div className='connected-container'> | ||
| {Object.keys(sizeDisplay).map((size, index) => { | ||
| const isActive = size === cardSize; | ||
|
|
||
| return ( | ||
| <label key={index} | ||
| className={isActive | ||
| ? "active connected-component" | ||
| : "connected-component" | ||
| } | ||
| > | ||
| <input checked={isActive} | ||
| className='radio-input' | ||
| name='card-size' | ||
| onChange={e => App.save("cardSize", e.currentTarget.value)} | ||
| type='radio' | ||
| value={size.toLowerCase()} /> | ||
| <div>{sizeDisplay[size]}</div> | ||
| </label> | ||
| ) | ||
| })} | ||
| return ( | ||
| <label key={index} | ||
| className={isActive | ||
| ? "active connected-component" | ||
| : "connected-component" | ||
| } | ||
| > | ||
| <input checked={isActive} | ||
| className='radio-input' | ||
| name='card-size' | ||
| onChange={e => dispatch(changeCardSize(e.currentTarget.value))} | ||
| type='radio' | ||
| value={size} /> | ||
| <div>{sizeDisplay[size]}</div> | ||
| </label> | ||
| ); | ||
| })} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
|
|
||
| const imgLanguageDisplay = { | ||
| "en": "English", | ||
| "fr": "French (Français)", | ||
| "es": "Spanish (Español)", | ||
| "de": "German (Deutsch)", | ||
| "it": "Italian (Italiano)", | ||
| "pt": "Portuguese (Português)", | ||
| "ja": "Japanese (日本語)", | ||
| "ko": "Korean (한국어)", | ||
| "ru": "Russian (Русский)", | ||
| "zhs": "Simplified Chinese (简体中文)", | ||
| "zht": "Traditional Chinese (繁體中文)" | ||
| ); | ||
| }; | ||
|
|
||
| const CardsImageLanguage = () => ( | ||
| <div className="cards-language"> | ||
| const CardsImageLanguage = () => { | ||
| const dispatch = useDispatch(); | ||
| const cardLang = useSelector(selectCardLang); | ||
| return ( | ||
| <div className="cards-language"> | ||
| Card image language: | ||
| <div className='connected-container'> | ||
| <select | ||
| value={App.state.cardLang} | ||
| onChange={e => App.save("cardLang", e.currentTarget.value)}> | ||
| {Object.entries(imgLanguageDisplay).map(([value, label]) => | ||
| <option key={value} value={value}>{label}</option> | ||
| )} | ||
| </select> | ||
| <div className='connected-container'> | ||
| <select | ||
| value={cardLang} | ||
| onChange={e => dispatch(changeCardLang(e.currentTarget.value))}> | ||
| {Object.entries(imgLanguageDisplay).map(([value, label]) => | ||
| <option key={value} value={value}>{label}</option> | ||
| )} | ||
| </select> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| ); | ||
| }; | ||
|
|
||
| export default GameSettings; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.