Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.

Commit 85e7d1f

Browse files
author
ricokahler
committed
working clean button
1 parent 01cf1a7 commit 85e7d1f

File tree

3 files changed

+68
-30
lines changed

3 files changed

+68
-30
lines changed

src/client/components/fa.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface FaProps {
1818
mask?: any;
1919
symbol?: any;
2020
color?: string;
21+
onClick?: any;
2122
}
2223

2324
export function Fa(props: FaProps) {

src/client/components/giant-autosuggest.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const DontSee = styled(Text)`
5959
`;
6060
const Search = styled.input`
6161
font-family: ${styles.fontFamily};
62-
font-size: ${styles.space(4)};
62+
font-size: ${styles.space(3)};
6363
outline: none;
6464
background-color: transparent;
6565
border: none;
@@ -75,8 +75,6 @@ interface GiantAutosuggestProps<T> {
7575
onSearch: (query: string) => void;
7676
renderSuggestion: (item: T, selected: boolean) => React.ReactNode;
7777
onSelectSuggestion: (key: string) => void;
78-
onFocus: (e: React.FocusEvent<HTMLInputElement>) => void;
79-
onBlur: (e: React.FocusEvent<HTMLInputElement>) => void;
8078
onClickDontSee: () => void;
8179
}
8280

@@ -99,6 +97,14 @@ export class GiantAutosuggest<T> extends React.PureComponent<
9997
suggestionsRef = React.createRef<HTMLElement>();
10098
searchRef = React.createRef<HTMLInputElement>();
10199

100+
componentDidMount() {
101+
if (this.props.focus) {
102+
const searchElement = this.searchRef.current;
103+
if (!searchElement) return;
104+
searchElement.focus();
105+
}
106+
}
107+
102108
async componentDidUpdate(
103109
previousProps: GiantAutosuggestProps<T>,
104110
previousState: GiantAutosuggestState,
@@ -201,14 +207,11 @@ export class GiantAutosuggest<T> extends React.PureComponent<
201207
};
202208

203209
renderContainer = (props: PopperContainerProps) => {
204-
const { onFocus, onBlur } = this.props;
205210
const { search } = this.state;
206211
return (
207212
<ClickAwayListener onClickAway={this.handleClose}>
208213
<Root {...props}>
209214
<Search
210-
onFocus={onFocus}
211-
onBlur={onBlur}
212215
type="search"
213216
value={search}
214217
innerRef={this.searchRef}

src/client/routes/welcome/welcome.tsx

+58-24
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import * as Model from 'models';
33
import * as styles from 'styles';
44
import styled from 'styled-components';
55
import { wait } from 'utilities/utilities';
6-
import { memoizeLast } from 'utilities/memoize-last';
76
import { searchList } from 'utilities/search-list';
87

98
import { View } from 'components/view';
109
import { Text, TextProps } from 'components/text';
1110
import { GiantAutosuggest } from 'components/giant-autosuggest';
1211
import { PrimaryButton } from 'components/button';
13-
import { Fa as _Fa } from 'components/fa';
12+
import { Fa } from 'components/fa';
1413
import { Paragraph } from 'components/paragraph';
1514
import { createInfoModal } from 'components/info-modal';
1615

@@ -27,7 +26,8 @@ const Slide = styled(View)`
2726
`;
2827
const Box = styled(View)`
2928
margin: auto;
30-
max-width: 64rem;
29+
width: 64rem;
30+
max-width: 100vw;
3131
align-items: flex-start;
3232
`;
3333
const Title = styled(Text)`
@@ -46,7 +46,7 @@ const Description = styled(Text)`
4646
font-size: ${styles.space(2)};
4747
margin-bottom: ${styles.space(0)};
4848
`;
49-
const Fa = styled(_Fa)`
49+
const Arrow = styled(Fa)`
5050
margin-left: ${styles.space(0)};
5151
`;
5252
const YearInfo = styled(Text)`
@@ -92,6 +92,27 @@ const NotPart = styled(Text)`
9292
color: ${styles.active(styles.beeKeeper)};
9393
}
9494
`;
95+
const SelectedDegree = styled(View)`
96+
flex-direction: row;
97+
align-items: center;
98+
margin-bottom: ${styles.space(0)};
99+
`;
100+
const SelectedDegreeName = styled(Text)`
101+
font-size: ${styles.space(3)};
102+
font-weight: bold;
103+
color: ${styles.turbo};
104+
flex: 1 1 auto;
105+
`;
106+
const Times = styled(Fa)`
107+
margin-left: ${styles.space(2)};
108+
color: ${styles.white};
109+
&:hover {
110+
color: ${styles.hover(styles.white)};
111+
}
112+
&:active {
113+
color: ${styles.active(styles.white)};
114+
}
115+
`;
95116

96117
interface WelcomeProps {
97118
degrees: Model.MasteredDegree.Model[];
@@ -119,11 +140,17 @@ export class Welcome extends React.PureComponent<WelcomeProps, WelcomeState> {
119140
notPartInfoModal = createInfoModal();
120141

121142
get degrees() {
122-
return this._getOrCalculateDegrees(this.props.degrees, this.state.search);
143+
return searchList(this.props.degrees, getDisplayText, this.state.search);
144+
}
145+
146+
get selectedDegreeName() {
147+
const { selectedDegreeId } = this.state;
148+
const { degrees } = this.props;
149+
if (!selectedDegreeId) return undefined;
150+
const selectedDegree = degrees.find(degree => degree.id === selectedDegreeId);
151+
if (!selectedDegree) return undefined;
152+
return selectedDegree.name;
123153
}
124-
_getOrCalculateDegrees = memoizeLast((degrees: Model.MasteredDegree.Model[], search: string) => {
125-
return searchList(degrees, getDisplayText, search);
126-
});
127154

128155
componentDidMount() {
129156
const buttonElement = this.buttonRef.current;
@@ -151,8 +178,9 @@ export class Welcome extends React.PureComponent<WelcomeProps, WelcomeState> {
151178
handleSelectDegree = (selectedDegreeId: string) => {
152179
this.setState({ selectedDegreeId });
153180
};
154-
handleFocus = (e: React.FocusEvent<HTMLInputElement>) => {};
155-
handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {};
181+
handleUnselectDegree = () => {
182+
this.setState({ selectedDegreeId: undefined });
183+
};
156184

157185
renderSuggestion = (degree: Model.MasteredDegree.Model, selected: boolean) => {
158186
return <Suggestion selected={selected}>{degree.name}</Suggestion>;
@@ -175,7 +203,7 @@ export class Welcome extends React.PureComponent<WelcomeProps, WelcomeState> {
175203
for your future.
176204
</Description>
177205
<PrimaryButton innerRef={this.buttonRef} onClick={this.handleGetStarted}>
178-
Get Started <Fa icon="chevronRight" />
206+
Get Started <Arrow icon="chevronRight" />
179207
</PrimaryButton>
180208
</Box>
181209
</Slide>
@@ -188,20 +216,26 @@ export class Welcome extends React.PureComponent<WelcomeProps, WelcomeState> {
188216
or ask your <Mail href="mailto:umd-cecs-undergrad@umich.edu">CECS advisor</Mail> if
189217
you need additional assistance.
190218
</YearInfo>
191-
<GiantAutosuggest
192-
focus={gotStarted}
193-
items={this.degrees}
194-
getDisplayText={getDisplayText}
195-
getKey={getKey}
196-
onSelectSuggestion={this.handleSelectDegree}
197-
renderSuggestion={this.renderSuggestion}
198-
onSearch={this.handleSearch}
199-
onFocus={this.handleFocus}
200-
onBlur={this.handleBlur}
201-
onClickDontSee={this.infoModal.open}
202-
/>
219+
{this.selectedDegreeName ? (
220+
<SelectedDegree>
221+
<SelectedDegreeName>{this.selectedDegreeName}</SelectedDegreeName>
222+
<Times icon="times" size="4x" onClick={this.handleUnselectDegree} />
223+
</SelectedDegree>
224+
) : (
225+
<GiantAutosuggest
226+
focus={gotStarted}
227+
items={this.degrees}
228+
getDisplayText={getDisplayText}
229+
getKey={getKey}
230+
onSelectSuggestion={this.handleSelectDegree}
231+
renderSuggestion={this.renderSuggestion}
232+
onSearch={this.handleSearch}
233+
onClickDontSee={this.infoModal.open}
234+
/>
235+
)}
236+
203237
<PrimaryButton>
204-
Let's begin <Fa icon="chevronRight" />
238+
Let's begin <Arrow icon="chevronRight" />
205239
</PrimaryButton>
206240
<NotPart onClick={this.notPartInfoModal.open}>
207241
Not part of the College of Engineering and Computer Science?

0 commit comments

Comments
 (0)