Skip to content

Commit 5c144ad

Browse files
committed
fixed autocomplete bug
1 parent 37f686d commit 5c144ad

File tree

12 files changed

+31
-69
lines changed

12 files changed

+31
-69
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# DO NOT PUT SECRETS HERE AS IT'S NOT GITIGNORED
22
# FOR local only, for production scripts/deploy.sh recreate .env file
33
# all env vars should be passed from CI/CD env (circleci) and starts with 'REACT_APP_' prefix
4+
REACT_APP_ASSETS_URL=https://kube-ts-server.s3.eu-west-2.amazonaws.com
5+
46
REACT_APP_API_URL=https://demo.mariuszrajczakowski.me/api/v1
57
# available values: dummy, sentry
68
REACT_APP_LOGGER_TYPE=dummy

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ build
6363
env-config.js
6464

6565
/k8s/override.yaml
66+
.env

assets/jscpd-badge.svg

Lines changed: 2 additions & 2 deletions
Loading

k8s/values-circleci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ secret: {}
33

44
configMap:
55
REACT_APP_API_URL: $REACT_APP_API_URL
6+
REACT_APP_ASSETS_URL: $REACT_APP_ASSETS_URL
67
REACT_APP_SENTRY_DSN: $REACT_APP_SENTRY_DSN
78
REACT_APP_LOGGER_TYPE: $REACT_APP_LOGGER_TYPE
89
REACT_APP_NODE_ENV: $REACT_APP_NODE_ENV

k8s/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ secret:
6969
# Configmap [remove "{}", uncomment and change the values below]
7070
configMap:
7171
{}
72+
# REACT_APP_ASSETS_URL: https://localhost:3000
7273
# REACT_APP_API_URL: https://localhost:9000/api/v1
7374
# REACT_APP_SENTRY_DSN: https://[email protected]/yourSentryNumber
7475
# REACT_APP_LOGGER_TYPE: sentry

src/atoms/Autocomplete/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,3 @@ const Autocomplete = ({value, onChange, suggestions}: any) => {
133133

134134
// tslint:disable-next-line:max-file-line-count
135135
export default Autocomplete;
136-

src/components/CourseSlide/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'slick-carousel/slick/slick-theme.css';
1515
import 'slick-carousel/slick/slick.css';
1616
import CourseRating from '../../atoms/CourseRating';
1717
import { EnhancedCourse } from '../../redux/discoveryItems/actionCreators';
18+
import assetsUrl from '../../utils/helpers/assetsUrl';
1819

1920
const Slide = ({
2021
course,
@@ -33,7 +34,7 @@ const Slide = ({
3334
<Link className={classes.courseLink} to={`/courses/${course.slug}`}>
3435
<CardMedia
3536
className={classes.cardMedia}
36-
image={course.imageUrl}
37+
image={assetsUrl(course.imageUrl)}
3738
title="Image title"
3839
/>
3940
<CardContent className={classes.cardContent}>

src/components/CourseView/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Redirect } from 'react-router-dom';
77
import { ROOT } from '../../constants/routes';
88
import { getCourseDetailsRequested } from '../../redux/courseDetails/actionCreators';
99
import { State } from '../../redux/rootReducer';
10+
import assetsUrl from '../../utils/helpers/assetsUrl';
1011
import useStyles from './styles';
1112

1213
export interface Params {
@@ -59,7 +60,7 @@ const CourseView = ({ match }: RouteComponentProps<Params>) => {
5960
</Grid>
6061
<Grid item xs={12} sm={3}>
6162
<Paper className={classes.paper}>
62-
<img src={course.imageUrl} style={{ width: '100%' }} />
63+
<img src={assetsUrl(course.imageUrl)} style={{ width: '100%' }} />
6364
<h4>{${coursePrice}`}</h4>
6465
<Button variant="contained" fullWidth color="primary">
6566
Add to cart

src/components/HeroContent/index.tsx

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import Container from '@material-ui/core/Container';
33
import Grid from '@material-ui/core/Grid';
44
import Typography from '@material-ui/core/Typography';
5+
import _isNil from 'ramda/src/isNil';
56
import React, { useState } from 'react';
67
import { useDispatch, useSelector } from 'react-redux';
78
import { useHistory } from 'react-router-dom';
@@ -11,69 +12,6 @@ import { State } from '../../redux/rootReducer';
1112
import Course from '../../types/items/Course';
1213
import User from '../../types/items/User';
1314
import useStyles from './styles';
14-
15-
const initialResults = [
16-
{ label: 'Afghanistan' },
17-
{ label: 'Aland Islands' },
18-
{ label: 'Albania' },
19-
{ label: 'Algeria' },
20-
{ label: 'American Samoa' },
21-
{ label: 'Andorra' },
22-
{ label: 'Angola' },
23-
{ label: 'Anguilla' },
24-
{ label: 'Antarctica' },
25-
{ label: 'Antigua and Barbuda' },
26-
{ label: 'Argentina' },
27-
{ label: 'Armenia' },
28-
{ label: 'Aruba' },
29-
{ label: 'Australia' },
30-
{ label: 'Austria' },
31-
{ label: 'Azerbaijan' },
32-
{ label: 'Bahamas' },
33-
{ label: 'Bahrain' },
34-
{ label: 'Bangladesh' },
35-
{ label: 'Barbados' },
36-
{ label: 'Belarus' },
37-
{ label: 'Belgium' },
38-
{ label: 'Belize' },
39-
{ label: 'Benin' },
40-
{ label: 'Bermuda' },
41-
{ label: 'Bhutan' },
42-
{ label: 'Bolivia, Plurinational State of' },
43-
{ label: 'Bonaire, Sint Eustatius and Saba' },
44-
{ label: 'Bosnia and Herzegovina' },
45-
{ label: 'Botswana' },
46-
{ label: 'Bouvet Island' },
47-
{ label: 'Brazil' },
48-
{ label: 'British Indian Ocean Territory' },
49-
{ label: 'Brunei Darussalam' },
50-
];
51-
52-
function getSuggestions(
53-
value: string | null,
54-
{ showEmpty }: { showEmpty: boolean } = { showEmpty: false }
55-
) {
56-
const inputValue = String(value)
57-
.trim()
58-
.toLowerCase();
59-
const inputLength = inputValue.length;
60-
let count = 0;
61-
62-
return inputLength === 0 && !showEmpty
63-
? []
64-
: initialResults.filter(suggestion => {
65-
const keep =
66-
count < 5 &&
67-
suggestion.label.slice(0, inputLength).toLowerCase() === inputValue;
68-
69-
if (keep) {
70-
count += 1;
71-
}
72-
73-
return keep;
74-
});
75-
}
76-
7715
export interface GetFormattedResultsOptions {
7816
readonly courses: Course[];
7917
readonly users: User[];
@@ -114,7 +52,7 @@ const HeroContent = () => {
11452

11553
const handleChange = (changes: any) => {
11654
// TODO: abstract this operations
117-
if (changes.hasOwnProperty('selectedItem')) {
55+
if (changes.hasOwnProperty('selectedItem') && !_isNil(changes.selectedItem)) {
11856
setValue(changes.selectedItem);
11957

12058
const item: any = results.filter(

src/config/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import getStringValue from '../utils/helpers/getStringValue';
33

44
export interface Config {
55
apiUrl: string;
6+
assetsUrl: string;
67
logger: LoggerFactoryOptions;
78
}
89

910
const env = (window as any)._env_;
1011

1112
const config: Config = {
1213
apiUrl: getStringValue(env.REACT_APP_API_URL, 'http://localhost:9000/api/v1'),
14+
assetsUrl: getStringValue(env.REACT_APP_ASSETS_URL, 'http://localhost:3000'),
1315
logger: {
1416
dummy: {
1517
silent:

0 commit comments

Comments
 (0)