Skip to content

Commit

Permalink
Merge pull request #322 from labzero/jeffrey/footer
Browse files Browse the repository at this point in the history
More TypeScript conversion
  • Loading branch information
JeffreyATW authored May 23, 2023
2 parents 8a56a40 + 824ddcb commit 65cc58f
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 79 deletions.
5 changes: 5 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ declare module "*.css" {
const style: Style;
export default style;
}

declare module "*.png" {
const value: string;
export default value;
}
8 changes: 4 additions & 4 deletions src/components/Flash/FlashContainer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { connect } from "react-redux";
import Flash from "./Flash";
import FlashComponent from "./Flash";
import { expireFlash } from "../../actions/flash";
import { Dispatch } from "../../interfaces";
import { Dispatch, Flash } from "../../interfaces";

const mapDispatchToProps = (dispatch: Dispatch, ownProps: { id: string }) => ({
const mapDispatchToProps = (dispatch: Dispatch, ownProps: Flash) => ({
expireFlash: () => {
dispatch(expireFlash(ownProps.id));
},
});

export default connect(null, mapDispatchToProps)(Flash);
export default connect(null, mapDispatchToProps)(FlashComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
* LICENSE.txt file in the root directory of this source tree.
*/

import PropTypes from "prop-types";
import React from "react";
import withStyles from "isomorphic-style-loader/withStyles";
import s from "./Footer.scss";

const Footer = ({ host }) => (
interface FooterProps {
host: string;
}

const Footer = ({ host }: FooterProps) => (
<div className={s.root}>
<div className={s.container}>
<a className={s.link} href={`//${host}/about`}>
Expand All @@ -34,8 +37,4 @@ const Footer = ({ host }) => (
</div>
);

Footer.propTypes = {
host: PropTypes.string.isRequired,
};

export default withStyles(s)(Footer);
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { connect } from "react-redux";
import Footer from "./Footer";
import { State } from "../../interfaces";

const mapStateToProps = (state) => ({
const mapStateToProps = (state: State) => ({
host: state.host,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
import PropTypes from "prop-types";
import React, { Component } from "react";
import { canUseDOM } from "fbjs/lib/ExecutionEnvironment";
import Button from "react-bootstrap/Button";
import withStyles from "isomorphic-style-loader/withStyles";
import s from "./GoogleInfoWindow.scss";

let google = {
maps: {
Marker: { MAX_ZINDEX: 1000000 },
places: { PlacesService: () => undefined, PlacesServiceStatus: {} },
},
};
let google: typeof window.google;

if (canUseDOM) {
google = window.google || google;
google = window.google;
}

class GoogleInfoWindow extends Component {
static propTypes = {
addRestaurant: PropTypes.func.isRequired,
map: PropTypes.any.isRequired,
placeId: PropTypes.string.isRequired,
};
interface GoogleInfoWindowProps {
addRestaurant: (restaurant: google.maps.places.PlaceResult) => void;
map: google.maps.Map;
placeId: string;
}

constructor(props) {
class GoogleInfoWindow extends Component<GoogleInfoWindowProps> {
placesService: google.maps.places.PlacesService;

constructor(props: GoogleInfoWindowProps) {
super(props);
this.placesService = new google.maps.places.PlacesService(props.map);
if (google) {
this.placesService = new google.maps.places.PlacesService(props.map);
}
}

handleClick = () => {
const { addRestaurant, placeId } = this.props;

this.placesService.getDetails({ placeId }, (result, status) => {
if (status === google.maps.places.PlacesServiceStatus.OK) {
if (status === google.maps.places.PlacesServiceStatus.OK && result) {
addRestaurant(result);
}
});
};

render() {
if (!google) {
return null;
}

return (
<div
className={s.root}
data-marker
style={{ zIndex: google.maps.Marker.MAX_ZINDEX * 2 }}
style={{
zIndex: google.maps.Marker.MAX_ZINDEX * 2,
}}
>
<div className={s.buttonContainer}>
<Button size="lg" variant="primary" onClick={this.handleClick}>
Expand Down
23 changes: 0 additions & 23 deletions src/components/GoogleInfoWindow/GoogleInfoWindowContainer.js

This file was deleted.

28 changes: 28 additions & 0 deletions src/components/GoogleInfoWindow/GoogleInfoWindowContainer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { connect } from "react-redux";
import { addRestaurant } from "../../actions/restaurants";
import { Dispatch } from "../../interfaces";
import GoogleInfoWindow from "./GoogleInfoWindow";

const mapDispatchToProps = (
dispatch: Dispatch,
ownProps: { placeId: string }
) => ({
addRestaurant: (result: google.maps.places.PlaceResult) => {
// eslint-disable-next-line camelcase
const { name, formatted_address } = result;
const location = result.geometry?.location;

return dispatch(
addRestaurant(
name || "",
ownProps.placeId,
// eslint-disable-next-line camelcase
formatted_address || "",
location?.lat() || 0,
location?.lng() || 0
)
);
},
});

export default connect(null, mapDispatchToProps)(GoogleInfoWindow);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext } from "react";

const GoogleMapsLoaderContext = createContext();
const GoogleMapsLoaderContext = createContext({});

export default GoogleMapsLoaderContext;
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@
* LICENSE.txt file in the root directory of this source tree.
*/

import PropTypes from "prop-types";
import React, { Component } from "react";
import withStyles from "isomorphic-style-loader/withStyles";
import { Flash } from "../../interfaces";
import HeaderLoginContainer from "../HeaderLogin/HeaderLoginContainer";
import FlashContainer from "../Flash/FlashContainer";
import MenuContainer from "../Menu/MenuContainer";
import Link from "../Link";
import Link from "../Link/Link";
import lunch from "./lunch.png";
import s from "./Header.scss";

class Header extends Component {
static propTypes = {
flashes: PropTypes.array.isRequired,
loggedIn: PropTypes.bool.isRequired,
// eslint-disable-next-line react/no-unused-prop-types
path: PropTypes.string,
};
interface HeaderProps {
flashes: Flash[];
loggedIn: boolean;
path: string;
}

static defaultProps = {
path: PropTypes.string,
};
interface HeaderState {
menuOpen: boolean;
prevPath: string | null;
}

static getDerivedStateFromProps(nextProps, state) {
class Header extends Component<HeaderProps, HeaderState> {
static getDerivedStateFromProps(nextProps: HeaderProps, state: HeaderState) {
if (nextProps.path !== state.prevPath) {
return {
menuOpen: false,
Expand All @@ -39,7 +39,7 @@ class Header extends Component {
return null;
}

constructor(props) {
constructor(props: HeaderProps) {
super(props);

this.state = {
Expand All @@ -52,14 +52,7 @@ class Header extends Component {
flashContainers = () => {
const { flashes } = this.props;

return flashes.map((flash) => (
<FlashContainer
message={flash.message}
type={flash.type}
id={flash.id}
key={flash.id}
/>
));
return flashes.map((flash) => <FlashContainer key={flash.id} {...flash} />);
};

closeMenu = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { connect } from "react-redux";
import { State } from "../../interfaces";
import { isLoggedIn } from "../../selectors/user";
import Header from "./Header";

const mapStateToProps = (state, ownProps) => ({
const mapStateToProps = (state: State, ownProps: { path: string }) => ({
flashes: state.flashes,
loggedIn: isLoggedIn(state),
path: ownProps.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ import PropTypes from "prop-types";
import React from "react";
import withStyles from "isomorphic-style-loader/withStyles";
import Button from "react-bootstrap/Button";
import { User } from "../../interfaces";
import s from "./HeaderLogin.scss";

const HeaderLogin = ({ user }) => {
interface HeaderLoginProps {
user: User;
}

const HeaderLogin = ({ user }: HeaderLoginProps) => {
let content = <div />;
if (user === null) {
content = (
<div className={s.root}>
<Button size="md" variant="primary" href="/login">
<Button variant="primary" href="/login">
Log in
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { connect } from "react-redux";
import { State } from "../../interfaces";
import HeaderLogin from "./HeaderLogin";

const mapStateToProps = (state) => ({ user: state.user });
const mapStateToProps = (state: State) => ({ user: state.user });

export default connect(mapStateToProps)(HeaderLogin);

0 comments on commit 65cc58f

Please sign in to comment.