From 58856872e22fabbaad1a5b6de1c1a70758d6e426 Mon Sep 17 00:00:00 2001 From: Derk Weijers Date: Tue, 4 Aug 2020 13:41:34 +0200 Subject: [PATCH 1/4] Launch Library 2 support --- src/common/Countdown.tsx | 5 ++-- src/components/CalendarCard.tsx | 8 +++--- src/components/Carousel.tsx | 2 +- src/components/Preview.tsx | 4 +-- src/components/ResultCard.tsx | 2 +- src/constants.ts | 2 +- src/helpers/status.tsx | 14 +++++----- src/screens/Calendar.tsx | 4 +-- src/screens/Dashboard.tsx | 2 +- src/screens/Details.tsx | 45 +++++++++++++++++---------------- src/screens/Search.tsx | 4 +-- src/stores/Launches.ts | 8 +++--- src/stores/Search.ts | 6 ++--- 13 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/common/Countdown.tsx b/src/common/Countdown.tsx index 364a1347..71ed12e5 100644 --- a/src/common/Countdown.tsx +++ b/src/common/Countdown.tsx @@ -37,13 +37,14 @@ const StatusText = styled.Text` let timer; const Countdown = ({ - wsstamp, + net, status, }: { - wsstamp: number; + net: Date; status?: number; }) => { const [timeLeft, setTimeLeft] = useState(0); + const wsstamp = new Date(net).getTime() / 1000 useEffect(() => { updateTimeLeft(); diff --git a/src/components/CalendarCard.tsx b/src/components/CalendarCard.tsx index 30db1809..502f4df1 100644 --- a/src/components/CalendarCard.tsx +++ b/src/components/CalendarCard.tsx @@ -43,12 +43,12 @@ const Desc = styled.Text` `; export default ({ data, isFirst = false }) => { - const launchTime = new Date(data.netstamp * 1000); + const launchTime = new Date(data.net); return ( - {data.netstamp === 0 ? ( + {launchTime.getTime() / 1000 === 0 ? ( TBD ) : ( <> @@ -59,10 +59,10 @@ export default ({ data, isFirst = false }) => { {data.name} - {data.location.name} + {data.pad.name} diff --git a/src/components/Carousel.tsx b/src/components/Carousel.tsx index 363f3f3c..49dd8ba7 100644 --- a/src/components/Carousel.tsx +++ b/src/components/Carousel.tsx @@ -56,7 +56,7 @@ const Carousel: React.FC = ({ launches, onItemPress }) => { return ( onItemPress(item)}> ( {data.name} - + ); diff --git a/src/components/ResultCard.tsx b/src/components/ResultCard.tsx index f4250e04..76031495 100644 --- a/src/components/ResultCard.tsx +++ b/src/components/ResultCard.tsx @@ -29,7 +29,7 @@ const ResultCard = ({ data, showDetails }) => { return ( showDetails(data)}> {name} - {net} + {new Date(net).toLocaleString()} ); }; diff --git a/src/constants.ts b/src/constants.ts index 25098c9b..a9beb05d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -8,7 +8,7 @@ export enum STATES { export const HEADER_HEIGHT = 50; export const TABBAR_HEIGHT = 70; -export const API_URL = "https://launchlibrary.net/1.4/"; +export const API_URL = "https://ll.thespacedevs.com/2.0.0/"; export const NEWS_API_URL = "https://spaceflightnewsapi.net/api/v1/"; diff --git a/src/helpers/status.tsx b/src/helpers/status.tsx index 013b0a50..cf7c4010 100644 --- a/src/helpers/status.tsx +++ b/src/helpers/status.tsx @@ -1,10 +1,12 @@ const STATUS_MESSAGES = [ - "Unknown Status", - "Launch is GO", - "Launch is NO-GO", - "Launch was a success", - "Launch failed", + "Launch is Go", + "Launch is To-Be-Determined", + "Launch was Successful", + "Launch was a Failure", + "Launch is in a Hold", + "Launch is In-Flight", + "Launch was a partial Failure" ]; export const getStatusMessage = (statusNumber: number) => - STATUS_MESSAGES[statusNumber] || "Unknown Status"; + STATUS_MESSAGES[statusNumber - 1] || "Unknown Status"; diff --git a/src/screens/Calendar.tsx b/src/screens/Calendar.tsx index ed0cb8b2..60159b67 100644 --- a/src/screens/Calendar.tsx +++ b/src/screens/Calendar.tsx @@ -66,7 +66,7 @@ const Calendar: React.FC = observer(({ navigation }) => { } let titleIndex = 0; - const sectionTitles = ["Scheduled", "To be defined"]; + const sectionTitles = ["Scheduled", "To be Determined"]; return ( @@ -80,7 +80,7 @@ const Calendar: React.FC = observer(({ navigation }) => { keyExtractor={(item) => item.id.toString()} renderItem={({ item }) => { const showTitle = - titleIndex === 0 || (item.netstamp === 0 && titleIndex === 1); + titleIndex === 0 || (new Date(item.net).getTime() / 1000 === 0 && titleIndex === 1); if (showTitle) titleIndex++; return ( <> diff --git a/src/screens/Dashboard.tsx b/src/screens/Dashboard.tsx index 1958b377..146fcbf6 100644 --- a/src/screens/Dashboard.tsx +++ b/src/screens/Dashboard.tsx @@ -61,7 +61,7 @@ const Dashboard = observer(() => { data={data} onPress={() => navigation.navigate("Details", { data })} /> - + ); } diff --git a/src/screens/Details.tsx b/src/screens/Details.tsx index 671c1860..d25302b9 100644 --- a/src/screens/Details.tsx +++ b/src/screens/Details.tsx @@ -81,8 +81,11 @@ const Details: React.FC = ({ route, navigation }) => { const appStateStore = useContext(AppState); const { data } = route.params; - const videoLink = data.vidURLs.length > 0 && data.vidURLs[0]; - const wikiLink = data.missions[0]?.wikiURL; + const videoLink = data.vidURLs && data.vidURLs.length > 0 && data.vidURLs[0].url; + const wikiLink = data.launch_service_provider.wiki_url; + const lspAbbrev = data.launch_service_provider.abbrev ? data.launch_service_provider.abbrev : "" + const missionType = data.mission ? data.mission.type : "Unknown" + const missionDescription = data.mission ? data.mission.description : "No Description Available" const actionItems = [ [ @@ -106,15 +109,15 @@ const Details: React.FC = ({ route, navigation }) => { thumbIcon: "Pin", thumbColor: "#2dcd55", action: () => { - const { longitude, latitude } = data.location.pads[0]; + const { latitude, longitude } = data.pad; + const lat = parseFloat(latitude) + const lon = parseFloat(longitude) firebase.analytics().logEvent("OPEN_MAPS", { value: data.name }); - openMap({ longitude, latitude }); + openMap({ latitude: lat, longitude: lon }); }, - disabled: !data.location.pads[0], - preview: !data.location.pads[0] && "Unavailable", }, { - title: "Wikipedia", + title: `${lspAbbrev} Wikipedia`, icon: "ChevronRight", preview: !wikiLink && "Unavailable", thumbIcon: "Globe", @@ -137,9 +140,9 @@ const Details: React.FC = ({ route, navigation }) => { return ( + /> = ({ route, navigation }) => { {data.name} - + Mission - {data.missions.map((mission) => ( - - diff --git a/src/screens/Search.tsx b/src/screens/Search.tsx index ce45c2ee..2504fb79 100644 --- a/src/screens/Search.tsx +++ b/src/screens/Search.tsx @@ -141,10 +141,10 @@ const SearchScreen = observer(({ navigation }) => { )} - openLink("https://launchlibrary.net/", appStateStore.browser) + openLink("https://thespacedevs.com/", appStateStore.browser) } > -
Data provided by the Launch Library
+
Data provided by Launch Library 2.0
diff --git a/src/stores/Launches.ts b/src/stores/Launches.ts index e1ec1df1..7e576daf 100644 --- a/src/stores/Launches.ts +++ b/src/stores/Launches.ts @@ -26,10 +26,10 @@ class Launches { loadNextLaunches = (numberOfLaunches = 10) => { this.state = STATES.LOADING; - fetch(`${API_URL}launch/next/${numberOfLaunches}`) + fetch(`${API_URL}launch/upcoming?limit=${numberOfLaunches}&mode=detailed`) .then((data) => data.json()) .then((data) => { - this.launches = data.launches; + this.launches = data.results; this.state = STATES.SUCCESS; }) .catch((err) => { @@ -44,11 +44,11 @@ class Launches { .logEvent("LOAD_MORE_LAUNCHES", { value: numberOfLaunches }); this.state = STATES.LOADING; fetch( - `${API_URL}launch/next/${numberOfLaunches}?offset=${this.launches.length}` + `${API_URL}launch/upcoming?limit=${numberOfLaunches}&offset=${this.launches.length}&mode=detailed` ) .then((data) => data.json()) .then((data) => { - this.launches = this.launches.concat(data.launches); + this.launches = this.launches.concat(data.results); this.state = STATES.SUCCESS; }) .catch((err) => { diff --git a/src/stores/Search.ts b/src/stores/Search.ts index bdd92897..b5f8d1fb 100644 --- a/src/stores/Search.ts +++ b/src/stores/Search.ts @@ -42,11 +42,11 @@ export class Search { searchLaunches = (str) => { this.state = STATES.LOADING; - fetch(`${API_URL}launch/${str}`) + fetch(`${API_URL}launch?search=${str}`) .then((data) => data.json()) .then((data) => { - this.results = data.launches || []; - this.totalResults = data.total; + this.results = data.results || []; + this.totalResults = data.count; this.state = STATES.SUCCESS; this.addHistoryItem(str); }) From e543d787d5d69db5702be6a8ebea9250ecb047b6 Mon Sep 17 00:00:00 2001 From: Derk Weijers Date: Tue, 4 Aug 2020 15:08:16 +0200 Subject: [PATCH 2/4] Launch Library 2 support --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c986646..f90eca9a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ![license: MIT](https://img.shields.io/github/license/mdubourg001/ssgo?style=flat-square) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) -A simple way to stay up to date with upcoming space launches, built with [React-Native](https://github.com/facebook/react-native), using the [Launch Library API](https://launchlibrary.net/) and the [Spaceflight News API](https://spaceflightnewsapi.net/). +A simple way to stay up to date with upcoming space launches, built with [React-Native](https://github.com/facebook/react-native), using the [Launch Library 2](https://thespacedevs.com/) and the [Spaceflight News API](https://spaceflightnewsapi.net/). ## Preview From 5856961e808581af99da11bc78731a89143dcb72 Mon Sep 17 00:00:00 2001 From: Derk Weijers Date: Wed, 5 Aug 2020 09:21:38 +0200 Subject: [PATCH 3/4] Updated the failing test with the new correct data --- src/components/__tests__/ResultCard.test.tsx | 2 +- src/components/__tests__/__snapshots__/ResultCard.test.tsx.snap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/__tests__/ResultCard.test.tsx b/src/components/__tests__/ResultCard.test.tsx index bb93c8aa..4e5a6787 100644 --- a/src/components/__tests__/ResultCard.test.tsx +++ b/src/components/__tests__/ResultCard.test.tsx @@ -7,7 +7,7 @@ describe("ResultCard", () => { const props = { data: { name: "$_TEST_NAME_$", - net: "$_TEST_NET_DATE_$", + net: "2020-08-05T02:00:00Z", }, showDetails: jest.fn(), }; diff --git a/src/components/__tests__/__snapshots__/ResultCard.test.tsx.snap b/src/components/__tests__/__snapshots__/ResultCard.test.tsx.snap index 94650abf..d003bb98 100644 --- a/src/components/__tests__/__snapshots__/ResultCard.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ResultCard.test.tsx.snap @@ -50,7 +50,7 @@ exports[`ResultCard renders correctly 1`] = ` ] } > - $_TEST_NET_DATE_$ + 8/5/2020, 4:00:00 AM
`; From e56be146f47b1cf94e5005171441ad9fb2d3cc2a Mon Sep 17 00:00:00 2001 From: Derk Weijers Date: Wed, 5 Aug 2020 09:52:09 +0200 Subject: [PATCH 4/4] Updated the notification logic with new timestamps --- src/stores/Launches.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stores/Launches.ts b/src/stores/Launches.ts index 7e576daf..50d13309 100644 --- a/src/stores/Launches.ts +++ b/src/stores/Launches.ts @@ -104,9 +104,9 @@ class Launches { if (plannedNotifications.length > 0) { PushNotificationIOS.cancelAllLocalNotifications(); } - if (data.wsstamp){ + if (data.net){ const fireDate = new Date( - (data.wsstamp - this.notifications.delay * 60) * 1000 + (data.net - this.notifications.delay * 60) * 1000 ); PushNotificationIOS.scheduleLocalNotification({ fireDate: fireDate.toISOString(), @@ -121,7 +121,7 @@ class Launches { if (this.notifications.enabled) { PushNotification.cancelAllLocalNotifications(); PushNotification.localNotificationSchedule({ - date: new Date(data.isostart), + date: new Date(data.net).toISOString(), message: `🚀 ${data.name} will launch in ${this.notifications.delay} minutes!`, }); }