Skip to content

Commit

Permalink
Merge pull request #35 from derkweijers/ll2-support
Browse files Browse the repository at this point in the history
Launch Library 2 support
  • Loading branch information
Illu committed Aug 5, 2020
2 parents 494f89a + e56be14 commit 4651599
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/common/Countdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/components/CalendarCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Wrapper isFirst={isFirst}>
<Row>
<DateWrapper>
{data.netstamp === 0 ? (
{launchTime.getTime() / 1000 === 0 ? (
<Day>TBD</Day>
) : (
<>
Expand All @@ -59,10 +59,10 @@ export default ({ data, isFirst = false }) => {
</DateWrapper>
<ContentWrapper>
<Desc bold>{data.name}</Desc>
<Desc numberOfLines={1}>{data.location.name}</Desc>
<Desc numberOfLines={1}>{data.pad.name}</Desc>
<Label
numberOfLines={2}
text={data.lsp.name.length < 50 ? data.lsp.name : data.lsp.abbrev}
text={data.launch_service_provider.name.length < 50 ? data.launch_service_provider.name : data.launch_service_provider.abbrev}
/>
</ContentWrapper>
</Row>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const Carousel: React.FC<Props> = ({ launches, onItemPress }) => {
return (
<ItemWrapper onPress={() => onItemPress(item)}>
<ParallaxImage
source={{ uri: item.rocket.imageURL }}
source={{ uri: item.image || item.rocket.configuration.image_url }}
containerStyle={styles.imageContainer}
style={styles.image}
parallaxFactor={0.2}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ interface Props {
const Preview = ({ data, onPress }): Props => (
<ItemWrapper onPress={onPress}>
<Thumbnail
source={{ uri: data.rocket.imageURL }}
source={{ uri: data.image || data.rocket.configuration.image_url }}
imageStyle={{ opacity: 0.9 }}
>
<Title>{data.name}</Title>
<Time>{data.windowstart}</Time>
<Time>{new Date(data.net).toLocaleString()}</Time>
</Thumbnail>
</ItemWrapper>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ResultCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const ResultCard = ({ data, showDetails }) => {
return (
<Wrapper onPress={() => showDetails(data)}>
<Title>{name}</Title>
<Subtitle>{net}</Subtitle>
<Subtitle>{new Date(net).toLocaleString()}</Subtitle>
</Wrapper>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/__tests__/ResultCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ exports[`ResultCard renders correctly 1`] = `
]
}
>
$_TEST_NET_DATE_$
8/5/2020, 4:00:00 AM
</Text>
</View>
`;
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/";

Expand Down
14 changes: 8 additions & 6 deletions src/helpers/status.tsx
Original file line number Diff line number Diff line change
@@ -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";
4 changes: 2 additions & 2 deletions src/screens/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const Calendar: React.FC<Props> = observer(({ navigation }) => {
}

let titleIndex = 0;
const sectionTitles = ["Scheduled", "To be defined"];
const sectionTitles = ["Scheduled", "To be Determined"];

return (
<Wrapper>
Expand All @@ -80,7 +80,7 @@ const Calendar: React.FC<Props> = 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 (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Dashboard = observer(() => {
data={data}
onPress={() => navigation.navigate("Details", { data })}
/>
<Countdown wsstamp={data.wsstamp} status={data.status} />
<Countdown net={data.net} status={data.status.id} />
</>
);
}
Expand Down
45 changes: 23 additions & 22 deletions src/screens/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ const Details: React.FC<Props> = ({ 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 = [
[
Expand All @@ -106,15 +109,15 @@ const Details: React.FC<Props> = ({ 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",
Expand All @@ -137,9 +140,9 @@ const Details: React.FC<Props> = ({ route, navigation }) => {
return (
<View style={{ overflow: "hidden" }}>
<Image
source={{ uri: data.rocket.imageURL }}
source={{ uri: data.image || data.rocket.configuration.image_url }}
style={{ transform: [{ scale: ImageScale }] }}
></Image>
/>
<Animated.ScrollView
contentContainerStyle={{ paddingTop: IMAGE_HEIGHT }}
onScroll={Animated.event(
Expand All @@ -152,33 +155,31 @@ const Details: React.FC<Props> = ({ route, navigation }) => {
<View style={{ backgroundColor: colors.background }}>
<ContentWrapper>
<Title>{data.name}</Title>
<Countdown wsstamp={data.wsstamp} status={data.status} />
<Countdown net={data.net} status={data.status.id} />
<Subtitle>Mission</Subtitle>
<DescWrapper>
{data.missions.map((mission) => (
<View key={mission.id}>
<Label text={mission.typeName} />
<View style={{ marginTop: 10 }}>
<DescText>{mission.description}</DescText>
</View>
<View>
<Label text={missionType} />
<View style={{ marginTop: 10 }}>
<DescText>{missionDescription}</DescText>
</View>
))}
{data.lsp.name && (
</View>
{data.launch_service_provider.name && (
<Row>
<Icon name="Briefcase" color={colors.accent} size={20} />
<PinLabel numberOfLines={2}>{data.lsp.name}</PinLabel>
<PinLabel numberOfLines={2}>{data.launch_service_provider.name}</PinLabel>
</Row>
)}
{data.net && (
<Row>
<Icon name="Clock" color={colors.accent} size={20} />
<PinLabel numberOfLines={2}>{data.net}</PinLabel>
<PinLabel numberOfLines={2}>{new Date(data.net).toLocaleString()}</PinLabel>
</Row>
)}
{data.location.name && (
{data.pad.name && (
<Row>
<Icon name="Pin" color={colors.accent} size={20} />
<PinLabel numberOfLines={2}>{data.location.name}</PinLabel>
<PinLabel numberOfLines={2}>{data.pad.location.name}</PinLabel>
</Row>
)}
</DescWrapper>
Expand Down
4 changes: 2 additions & 2 deletions src/screens/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ const SearchScreen = observer(({ navigation }) => {
)}
<TouchableOpacity
onPress={() =>
openLink("https://launchlibrary.net/", appStateStore.browser)
openLink("https://thespacedevs.com/", appStateStore.browser)
}
>
<Footer>Data provided by the Launch Library</Footer>
<Footer>Data provided by Launch Library 2.0</Footer>
</TouchableOpacity>
</ScrollWrapper>
</ContentWrapper>
Expand Down
14 changes: 7 additions & 7 deletions src/stores/Launches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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(),
Expand All @@ -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!`,
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/stores/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down

0 comments on commit 4651599

Please sign in to comment.