Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Hotels: Set price stats to HotelsContext for stay22
Browse files Browse the repository at this point in the history
Add complete flow types for decimal-light.
  • Loading branch information
tbergquist-godaddy committed May 24, 2019
1 parent 9fc728d commit 7a2c14f
Show file tree
Hide file tree
Showing 9 changed files with 779 additions and 70 deletions.
576 changes: 567 additions & 9 deletions app/core/config/flow-typed/npm/decimal.js-light.js

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion app/hotels/src/allHotels/Stay22PaginationContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type RelayPaginationProp,
} from '@kiwicom/mobile-relay';
import { Logger } from '@kiwicom/mobile-shared';
import { Decimal } from 'decimal.js-light';

import type { Stay22PaginationContainer_data as Stay22PaginationContainerType } from './__generated__/Stay22PaginationContainer_data.graphql';
import { HotelsContext, type HotelsContextState } from '../HotelsContext';
Expand All @@ -19,7 +20,15 @@ type Props = {|

export function Stay22PaginationContainer(props: Props) {
const [isLoading, setIsLoading] = React.useState(false);
const { closeHotels }: HotelsContextState = React.useContext(HotelsContext);
const {
closeHotels,
actions: { setCurrentSearchStats },
}: HotelsContextState = React.useContext(HotelsContext);

const priceMax =
props.data.allAvailableStay22Hotels?.stats?.minPrice?.amount ?? 0;
const priceMin =
props.data.allAvailableStay22Hotels?.stats?.maxPrice?.amount ?? 0;

React.useEffect(() => {
Logger.ancillaryDisplayed(
Expand All @@ -28,6 +37,13 @@ export function Stay22PaginationContainer(props: Props) {
);
}, []);

React.useEffect(() => {
setCurrentSearchStats({
priceMax: new Decimal(priceMax).toNumber(),
priceMin: new Decimal(priceMin).toNumber(),
});
}, [priceMax, priceMin, setCurrentSearchStats]);

function loadMore() {
if (props.relay.hasMore() && !props.relay.isLoading()) {
setIsLoading(true);
Expand Down Expand Up @@ -62,6 +78,14 @@ export default createPaginationContainer(
@connection(
key: "Stay22PaginationContainer_allAvailableStay22Hotels"
) {
stats {
minPrice {
amount
}
maxPrice {
amount
}
}
edges {
node {
... on AllAvailableStay22Hotel {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7a2c14f

Please sign in to comment.