Skip to content

Commit 377d61c

Browse files
authored
Merge pull request #78 from TravisL12/fix-day-count
Fix day count
2 parents 752a00e + 88cb3ec commit 377d61c

4 files changed

Lines changed: 51 additions & 20 deletions

File tree

src/hooks/useNavigation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
THistoryItem,
1919
TNavigationButton,
2020
TUseNavigationProps,
21+
TAppOptions,
2122
} from '../pages/types';
2223
import {
2324
adjacentDate,
@@ -27,6 +28,10 @@ import {
2728
trimDateString,
2829
} from '../utilities';
2930

31+
const incrementDayCount = (options: TAppOptions) => {
32+
setChrome({ [TODAY_COUNT]: options[TODAY_COUNT] + 1 });
33+
};
34+
3035
export const useNavigation = ({
3136
response,
3237
options,
@@ -155,6 +160,7 @@ export const useNavigation = ({
155160

156161
if (options[IS_TODAY_LIMIT_ON] && showToday) {
157162
showToday = options[TODAY_COUNT] < options[TODAY_LIMIT];
163+
incrementDayCount(options);
158164
}
159165

160166
showToday ? fetchToday() : fetchRandom();

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Displays the Astronomy Picture of the Day (APOD) and allows you to review similar images of planets, stars, galaxies and nebulas",
55
"options_page": "popup.html",
66
"short_name": "APOD by The Trav",
7-
"version": "4.1.3",
7+
"version": "4.1.4",
88
"background": { "service_worker": "background.bundle.js" },
99
"action": {
1010
"default_popup": "popup.html",

src/pages/Popup/Popup.jsx

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
DEFAULT_OPTIONS,
99
APOD_OPTIONS,
1010
TODAY_LIMIT_COUNT,
11+
TODAY_LIMIT,
1112
} from '../../constants';
1213
import { getChrome, setChrome } from '../../utilities';
1314
import {
@@ -42,7 +43,8 @@ const optionsConfig = [
4243
{
4344
id: IS_TODAY_LIMIT_ON,
4445
label: 'Switch from Today to Random',
45-
description: `Show today's APOD ${TODAY_LIMIT_COUNT} times and then will switch to random APOD's.`,
46+
description: `Show today's APOD multiple times and then will switch to random APOD's.
47+
Use the input below to set the limit.`,
4648
type: 'checkbox',
4749
},
4850
];
@@ -74,24 +76,42 @@ const Popup = () => {
7476
<SPopupContainer>
7577
<h3>Options</h3>
7678
<SOptionsContainer>
77-
{optionsConfig.map((option) => {
78-
return (
79-
<SOption key={option.id} className="option">
80-
<div className="info">
81-
<label htmlFor={option.id}>{option.label}</label>
82-
<div className="sub-info">{option.description}</div>
83-
</div>
84-
<div className="inputs">
85-
<input
86-
onChange={handleCheckboxChange}
87-
type={option.type}
88-
id={option.id}
89-
checked={popupOptions[option.id]}
90-
/>
91-
</div>
92-
</SOption>
93-
);
94-
})}
79+
{optionsConfig.map((option) => (
80+
<SOption key={option.id}>
81+
<div className="info">
82+
<label htmlFor={option.id}>{option.label}</label>
83+
<div className="sub-info">{option.description}</div>
84+
</div>
85+
<div className="inputs">
86+
<input
87+
onChange={handleCheckboxChange}
88+
type={option.type}
89+
id={option.id}
90+
checked={popupOptions[option.id]}
91+
/>
92+
</div>
93+
</SOption>
94+
))}
95+
<SOption>
96+
<div className="info">
97+
<label htmlFor={'today-count'}>Today Limit</label>
98+
<div className="sub-info">
99+
The APOD for today will be shown this number of times before
100+
switching to random.
101+
</div>
102+
</div>
103+
<div className="inputs">
104+
<input
105+
disabled={!popupOptions[IS_TODAY_LIMIT_ON]}
106+
onChange={(event) => {
107+
setChrome({ [TODAY_LIMIT]: +event.target.value });
108+
}}
109+
defaultValue={popupOptions[TODAY_LIMIT]}
110+
type="number"
111+
id="today-count"
112+
/>
113+
</div>
114+
</SOption>
95115
</SOptionsContainer>
96116
<SAboutApod>
97117
<p>

src/pages/Popup/styles.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export const SOption = styled.div`
2727
margin-top: 4px;
2828
color: #444;
2929
}
30+
31+
input[type='number'] {
32+
width: 50px;
33+
text-align: right;
34+
}
3035
`;
3136

3237
export const SAboutApod = styled.div``;

0 commit comments

Comments
 (0)