Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Gupta authored and Rahul Gupta committed Jul 24, 2024
1 parent 6613e85 commit 9836450
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 14 deletions.
29 changes: 26 additions & 3 deletions src/editor/components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { ScenesModal } from './modals/ScenesModal';
import { PaymentModal } from './modals/PaymentModal';
import { SceneEditTitle } from './components/SceneEditTitle';
import { AddLayerPanel } from './components/AddLayerPanel';
import { removeEntity } from '../lib/entity.js';

import posthog from 'posthog-js';

THREE.ImageUtils.crossOrigin = '';
Expand All @@ -38,6 +40,7 @@ export default class Main extends Component {
isProfileModalOpened: false,
isAddLayerPanelOpen: false,
isGeoModalOpened: false,
geoEnabled: false,
isScenesModalOpened: !isStreetLoaded,
isPaymentModalOpened: isPaymentModalOpened,
sceneEl: AFRAME.scenes[0],
Expand Down Expand Up @@ -172,6 +175,7 @@ export default class Main extends Component {
};

onCloseSignInModal = () => {
console.log('closed');
this.setState({ isSignInModalOpened: false });
};

Expand All @@ -183,13 +187,32 @@ export default class Main extends Component {
this.setState({ isProfileModalOpened: false });
};

onCloseGeoModal = () => {
this.setState({ isGeoModalOpened: false });
onCloseGeoModal = (user) => {
console.log('im running geo');
if (!user) {
this.setState({ isSignInModalOpened: true });
} else if (user && !user.isPro) {
this.setState({
isGeoModalOpened: false,
isPaymentModalOpened: true,
geoEnabled: true
});
}
};

onClosePaymentModal = () => {
onClosePaymentModal = (user) => {
console.log('im running');

window.location.hash = '#';
this.setState({ isPaymentModalOpened: false });
if (!user.isPro && this.state.geoEnabled) {
STREET.notify.warningMessage('geospatial features require pro plan');
const element = document.querySelector(
'[data-layer-name="Google 3D Tiles"]'
);
removeEntity(element, true);
this.setState({ geoEnabled: false });
}
};

toggleEdit = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function create3DTiles() {
latitude: ${latitude}; longitude: ${longitude}; elevation: ${elevation}; maps: google3d
`
);
console.log(geoLayer);
// update sceneGraph
Events.emit('entitycreated', geoLayer);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import posthog from 'posthog-js';
const GeoPanel = () => {
const { currentUser } = useAuthContext();
const onClick = () => {
posthog.capture('geo_panel_clicked');
posthog.capture('geo_panel_clicked', { user_id: currentUser?.uid });
if (!currentUser) {
STREET.notify.warningMessage(
'Please sign in to use geospatial features.'
);
Events.emit('opensigninmodal');
} else if (currentUser.isPro) {
Events.emit('opengeomodal');
} else {
Events.emit('openpaymentmodal');
Events.emit('opengeomodal');
}
};

Expand Down
34 changes: 29 additions & 5 deletions src/editor/components/modals/GeoModal/GeoModal.component.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useState, useCallback, useEffect } from 'react';
import { useAuthContext } from '../../../contexts/index.js';

import styles from './GeoModal.module.scss';
import { Mangnifier20Icon, Save24Icon, QR32Icon } from '../../../icons';

import { firebaseConfig } from '../../../services/firebase.js';
import Modal from '../Modal.jsx';
import { Button, Input } from '../../components/index.js';
import { Button, Input, Toggle } from '../../components/index.js';
import {
GoogleMap,
useJsApiLoader,
Expand All @@ -15,19 +16,25 @@ import {
import GeoImg from '../../../../../ui_assets/geo.png';
import { roundCoord } from '../../../../../src/utils.js';
import { QrCode } from '../../components/QrCode/QrCode.component.jsx';
import {
create3DTiles,
createMapbox
} from '../../components/AddLayerPanel/createLayerFunctions.js';

const GeoModal = ({ isOpen, onClose }) => {
const { isLoaded } = useJsApiLoader({
googleMapsApiKey: firebaseConfig.apiKey
});

const { currentUser } = useAuthContext();
const [markerPosition, setMarkerPosition] = useState({
lat: 37.7637072, // lat: 37.76370724481858, lng: -122.41517686259827
lng: -122.4151768
});
const [elevation, setElevation] = useState(10);
const [autocomplete, setAutocomplete] = useState(null);
const [qrCodeUrl, setQrCodeUrl] = useState(null);
const [is3D, setIs3D] = useState(true);

useEffect(() => {
if (isOpen) {
Expand Down Expand Up @@ -92,6 +99,9 @@ const GeoModal = ({ isOpen, onClose }) => {
setElevation(newElevation);
};

const handle3DToggle = (value) => {
setIs3D(value);
};
const onAutocompleteLoad = useCallback((autocompleteInstance) => {
setAutocomplete(autocompleteInstance);
}, []);
Expand All @@ -111,10 +121,11 @@ const GeoModal = ({ isOpen, onClose }) => {
}, [autocomplete]); // eslint-disable-line react-hooks/exhaustive-deps

const onCloseCheck = (evt) => {
console.log('running check');
// do not close geoModal when clicking on a list with suggestions for addresses
const autocompleteContatiner = document.querySelector('.pac-container');
if (autocompleteContatiner.children.length === 0) {
onClose();
onClose(currentUser);
}
};

Expand Down Expand Up @@ -145,8 +156,13 @@ const GeoModal = ({ isOpen, onClose }) => {
'street-geo',
`latitude: ${latitude}; longitude: ${longitude}; elevation: ${elevation}`
);

onClose();
if (is3D) {
create3DTiles();
} else {
createMapbox();
}
console.log(currentUser);
onClose(currentUser);
};

return (
Expand Down Expand Up @@ -211,6 +227,14 @@ const GeoModal = ({ isOpen, onClose }) => {
onChange={handleElevationChange}
></Input>
</div>
<div>
<p>3D Enabled</p>
<Toggle
status={is3D}
onChange={handle3DToggle}
label={{ text: 'Google 3D Tiles' }}
/>
</div>
</div>

{qrCodeUrl && (
Expand Down Expand Up @@ -238,7 +262,7 @@ const GeoModal = ({ isOpen, onClose }) => {
variant="filled"
onClick={onSaveHandler}
>
Update Scene Location
Update Scene
</Button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ const PaymentModal = ({ isOpen, onClose }) => {
setIsLoading(false);
};

const closeWrapper = () => {
onClose(currentUser);
};

return (
<Modal
className={styles.modalWrapper}
isOpen={isOpen}
onClose={onClose}
extraCloseKeyCode={72}
onClose={closeWrapper}
>
<div className={styles.paymentDetails}>
<h3>Unlock Geospatial Features with 3DStreet Pro</h3>
Expand Down
1 change: 1 addition & 0 deletions src/editor/contexts/Auth.context.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const AuthProvider = ({ children }) => {
};

const unsubscribe = auth.onAuthStateChanged((user) => {
console.log('auth changed');
fetchUserData(user);
});

Expand Down

0 comments on commit 9836450

Please sign in to comment.