Skip to content

Commit 875d9be

Browse files
authored
Merge pull request #31 from TravisL12/api-history
New API & New History View
2 parents 17bf24f + bcd7bf4 commit 875d9be

15 files changed

Lines changed: 275 additions & 178 deletions

File tree

public/manifest.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Astronomy Picture of the Day APOD by The Trav",
55
"short_name": "APOD by The Trav",
66
"description": "Displays the Astronomy Picture of the Day (APOD) and allows you to review similar images of planets, stars, galaxies and nebulas",
7-
"version": "3.4.3",
7+
"version": "3.5.0",
88

99
"browser_action": {
1010
"default_icon": "sun_icon.png",
@@ -30,11 +30,5 @@
3030
"newtab": "index.html"
3131
},
3232

33-
"permissions": [
34-
"topSites",
35-
"storage",
36-
"https://api.nasa.gov/*",
37-
"https://apod.nasa.gov/cgi-bin/apod/apod_search",
38-
"https://www.google-analytics.com/collect"
39-
]
33+
"permissions": ["topSites", "storage", "https://apodapi.herokuapp.com/*"]
4034
}

public/options.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ <h3>
6262
</div>
6363
</div>
6464

65+
<div class="option">
66+
<div class="info">
67+
<span>Show History</span>
68+
<div class="sub-info">
69+
This will show/hide the history row at the bottom of the page.
70+
</div>
71+
</div>
72+
<div class="inputs">
73+
<input
74+
type="checkbox"
75+
id="history-row-toggle"
76+
name="show-history-row"
77+
/>
78+
</div>
79+
</div>
80+
6581
<div class="option">
6682
<div class="info">
6783
<span>Switch from Today to Random</span>

public/options.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,26 @@ const defaultOptions = {
88
apodType: "random",
99
hiResOnly: false,
1010
showTopSites: true,
11+
showHistoryRow: true,
1112
isTodayLimitOn: false,
12-
todayLimit: 5
13+
todayLimit: 5,
1314
};
1415
const optionsForm = {
1516
chooseApod: optionsEl["choose-apod"],
1617
highResOnly: optionsEl["high-res-only"],
1718
showTopSites: optionsEl["show-top-sites"],
19+
showHistoryRow: optionsEl["show-history-row"],
1820
isTodayLimitOn: optionsEl["show-today-limit"],
19-
todayCountInput: optionsEl["today-count-input"]
21+
todayCountInput: optionsEl["today-count-input"],
2022
};
2123

2224
const syncGetOptions = [
2325
"apodType",
2426
"hiResOnly",
2527
"showTopSites",
28+
"showHistoryRow",
2629
"isTodayLimitOn",
27-
"todayLimit"
30+
"todayLimit",
2831
];
2932

3033
function storageSync(fn) {
@@ -65,6 +68,10 @@ class ApodOptions {
6568
saveOption({ showTopSites: optionsForm.showTopSites.checked });
6669
}
6770

71+
saveHistoryRowToggle() {
72+
saveOption({ showHistoryRow: optionsForm.showHistoryRow.checked });
73+
}
74+
6875
saveTodayCountInput() {
6976
const todayLimit = parseInt(optionsForm.todayCountInput.value);
7077
saveOption({ todayLimit });
@@ -84,13 +91,21 @@ class ApodOptions {
8491
this.createListener(optionsForm.chooseApod[1], this.saveApodType);
8592
this.createListener(optionsForm.highResOnly, this.saveHiResOnly);
8693
this.createListener(optionsForm.showTopSites, this.saveTopSitesToggle);
94+
this.createListener(optionsForm.showHistoryRow, this.saveHistoryRowToggle);
8795
this.createListener(optionsForm.todayCountInput, this.saveTodayCountInput);
8896
this.createListener(optionsForm.isTodayLimitOn, this.saveIsTodayLimitOn);
8997
}
9098

9199
setDefaultValues() {
92100
storageSync(
93-
({ apodType, hiResOnly, showTopSites, isTodayLimitOn, todayLimit }) => {
101+
({
102+
apodType,
103+
hiResOnly,
104+
showTopSites,
105+
showHistoryRow,
106+
isTodayLimitOn,
107+
todayLimit,
108+
}) => {
94109
const options = {};
95110

96111
if (!apodType) {
@@ -102,6 +117,9 @@ class ApodOptions {
102117
if (showTopSites === undefined) {
103118
options.showTopSites = defaultOptions.showTopSites;
104119
}
120+
if (showHistoryRow === undefined) {
121+
options.showHistoryRow = defaultOptions.showHistoryRow;
122+
}
105123
if (isTodayLimitOn === undefined) {
106124
options.isTodayLimitOn = defaultOptions.isTodayLimitOn;
107125
}
@@ -116,10 +134,18 @@ class ApodOptions {
116134

117135
loadOptions() {
118136
storageSync(
119-
({ apodType, hiResOnly, showTopSites, isTodayLimitOn, todayLimit }) => {
137+
({
138+
apodType,
139+
hiResOnly,
140+
showTopSites,
141+
showHistoryRow,
142+
isTodayLimitOn,
143+
todayLimit,
144+
}) => {
120145
optionsEl[apodType].checked = true;
121146
optionsForm.highResOnly.checked = hiResOnly;
122147
optionsForm.showTopSites.checked = showTopSites;
148+
optionsForm.showHistoryRow.checked = showHistoryRow;
123149
optionsForm.isTodayLimitOn.checked = isTodayLimitOn;
124150
optionsForm.todayCountInput.value = todayLimit;
125151
optionsForm.todayCountInput.disabled = !isTodayLimitOn;

src/ajax-loader-black.gif

-3.13 KB
Binary file not shown.

src/components/Apod.js

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ import Drawer from "./Drawer";
99
import Title from "./Title";
1010
import TopSites from "./TopSites";
1111
import { TitleLoader } from "./LoadingSpinner";
12-
import { thumbSourceLink, KEY_MAP, APOD_API_URL, API_KEY } from "../utilities";
12+
import { KEY_MAP, APOD_API_URL } from "../utilities";
1313
import {
1414
adjacentDate,
1515
isToday,
1616
today,
1717
randomDate,
18-
MIN_APOD_DATE
18+
MIN_APOD_DATE,
1919
} from "../utilities/dateUtility";
2020
import HistoryHelper from "../utilities/history";
2121
import Preload from "../utilities/preload-utility";
22+
import HistoryRow from "./HistoryRow";
2223

2324
const MAX_ERROR_TRIES = 3;
2425
const ERROR_MESSAGE = "NASA APOD Error: Please reload or try Again Later";
@@ -31,17 +32,18 @@ class Apod extends Component {
3132
selection: string,
3233
isHighRes: bool,
3334
showTopSites: bool,
35+
showHistoryRow: bool,
3436
showTodayOptions: shape({
3537
count: number,
3638
limit: number,
37-
isLimitOn: bool
39+
isLimitOn: bool,
3840
}),
3941
favorites: objectOf(
4042
shape({
4143
url: string,
42-
title: string
44+
title: string,
4345
})
44-
)
46+
),
4547
};
4648

4749
state = {
@@ -50,14 +52,14 @@ class Apod extends Component {
5052
isLoading: true,
5153
isImageHD: false,
5254
hasLoadingError: false,
53-
videoUrl: undefined
55+
videoUrl: undefined,
5456
};
5557

5658
componentDidMount() {
5759
const bypassLoadCount = true;
5860
const {
5961
selection,
60-
showTodayOptions: { count, limit, isLimitOn }
62+
showTodayOptions: { count, limit, isLimitOn },
6163
} = this.props;
6264

6365
const chooseRandom =
@@ -74,7 +76,7 @@ class Apod extends Component {
7476
this.setState({ isLoading: true, response: undefined });
7577
};
7678

77-
specificDate = date => {
79+
specificDate = (date) => {
7880
this.getImage(date);
7981
};
8082

@@ -120,7 +122,11 @@ class Apod extends Component {
120122

121123
getImage = (date, errorCount = 0) => {
122124
this.setLoading();
123-
const params = { date, api_key: API_KEY };
125+
const params = {
126+
date,
127+
image_thumbnail_size: 450,
128+
absolute_thumbnail_url: true,
129+
};
124130
axios.get(APOD_API_URL, { params }).then(
125131
({ data }) => this.loadApod(data),
126132
() => this.errorApod(errorCount)
@@ -139,22 +145,22 @@ class Apod extends Component {
139145

140146
saveFavorite = () => {
141147
const { favorites } = this.props;
142-
const { date, title } = this.state.response;
148+
const { date, title, image_thumbnail } = this.state.response;
143149

144150
if (!favorites || !favorites[date]) {
145151
chrome.storage.sync.set({
146152
apodFavorites: {
147153
...favorites,
148154
[date]: {
149155
title,
150-
imgUrl: thumbSourceLink(date)
151-
}
152-
}
156+
imgUrl: image_thumbnail,
157+
},
158+
},
153159
});
154160
}
155161
};
156162

157-
loadApod = response => {
163+
loadApod = (response) => {
158164
const { isHighRes } = this.props;
159165
historyHelper.add(response);
160166
if (response.media_type === "video") {
@@ -164,7 +170,7 @@ class Apod extends Component {
164170
response,
165171
videoUrl,
166172
apodImage: undefined,
167-
isLoading: false
173+
isLoading: false,
168174
});
169175
} catch (err) {
170176
console.log(err);
@@ -175,7 +181,7 @@ class Apod extends Component {
175181
}
176182
};
177183

178-
errorApod = errorCount => {
184+
errorApod = (errorCount) => {
179185
if (errorCount >= MAX_ERROR_TRIES) {
180186
this.setState({ hasLoadingError: true });
181187
} else {
@@ -206,7 +212,7 @@ class Apod extends Component {
206212
response,
207213
isImageHD,
208214
isLoading: false,
209-
apodImage: loadedImage
215+
apodImage: loadedImage,
210216
});
211217
};
212218

@@ -216,14 +222,14 @@ class Apod extends Component {
216222
};
217223

218224
render() {
219-
const { favorites, showTopSites } = this.props;
225+
const { favorites, showTopSites, showHistoryRow } = this.props;
220226
const {
221227
response,
222228
apodImage,
223229
isImageHD,
224230
isLoading,
225231
hasLoadingError,
226-
videoUrl
232+
videoUrl,
227233
} = this.state;
228234

229235
const handlers = {
@@ -244,7 +250,7 @@ class Apod extends Component {
244250
},
245251
NEXT_HISTORY: () => {
246252
this.recallHistory(true);
247-
}
253+
},
248254
};
249255

250256
const dateNavigation = {
@@ -253,11 +259,11 @@ class Apod extends Component {
253259
current: this.current,
254260
random: this.random,
255261
forceHighDef: this.forceHighDef,
256-
saveFavorite: this.saveFavorite
262+
saveFavorite: this.saveFavorite,
257263
};
258264

259265
const headerStyle = {
260-
justifyContent: showTopSites ? "space-between" : "flex-end"
266+
justifyContent: showTopSites ? "space-between" : "flex-end",
261267
};
262268

263269
return (
@@ -286,8 +292,14 @@ class Apod extends Component {
286292
response={response}
287293
favorites={favorites}
288294
specificDate={this.specificDate}
289-
historyHelper={historyHelper}
290295
/>
296+
{showHistoryRow && (
297+
<HistoryRow
298+
historyHelper={historyHelper}
299+
specificDate={this.specificDate}
300+
activeResponse={response}
301+
/>
302+
)}
291303
</div>
292304
</GlobalHotKeys>
293305
);

0 commit comments

Comments
 (0)