From 18be7e13eec4162f43e43fb4c68ab2cf0af7cee3 Mon Sep 17 00:00:00 2001 From: arielherself Date: Fri, 24 Nov 2023 16:32:07 +0800 Subject: [PATCH] chore(repo): recover tree structure --- .gitignore | 18 + .idea/workspace.xml | 92 + README.md | 1623 ++++ package-lock.json | 17763 +++++++++++++++++++++++++++++++++++++++++ package.json | 35 + public/favicon.ico | Bin 0 -> 24838 bytes public/index.html | 34 + src/App.css | 24 + src/App.js | 18 + src/App.test.js | 8 + src/Networking.js | 16 + src/SimulateClick.js | 12 + src/UMap.js | 170 + src/index.css | 5 + src/index.js | 9 + src/logo.svg | 7 + 16 files changed, 19834 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/workspace.xml create mode 100644 README.md create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 public/favicon.ico create mode 100644 public/index.html create mode 100644 src/App.css create mode 100644 src/App.js create mode 100644 src/App.test.js create mode 100644 src/Networking.js create mode 100644 src/SimulateClick.js create mode 100644 src/UMap.js create mode 100644 src/index.css create mode 100644 src/index.js create mode 100644 src/logo.svg diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..927d17b --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# See https://help.github.com/ignore-files/ for more about ignoring files. + +# dependencies +/node_modules + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env +npm-debug.log* +yarn-debug.log* +yarn-error.log* + diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..369b867 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +``` + +Then, on the server, you can replace `__SERVER_DATA__` with a JSON of real data right before sending the response. The client code can then read `window.SERVER_DATA` to use it. **Make sure to [sanitize the JSON before sending it to the client](https://medium.com/node-security/the-most-common-xss-vulnerability-in-react-js-applications-2bdffbcc1fa0) as it makes your app vulnerable to XSS attacks.** + +## Running Tests + +>Note: this feature is available with `react-scripts@0.3.0` and higher.
+>[Read the migration guide to learn how to enable it in older projects!](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md#migrating-from-023-to-030) + +Create React App uses [Jest](https://facebook.github.io/jest/) as its test runner. To prepare for this integration, we did a [major revamp](https://facebook.github.io/jest/blog/2016/09/01/jest-15.html) of Jest so if you heard bad things about it years ago, give it another try. + +Jest is a Node-based runner. This means that the tests always run in a Node environment and not in a real browser. This lets us enable fast iteration speed and prevent flakiness. + +While Jest provides browser globals such as `window` thanks to [jsdom](https://github.com/tmpvar/jsdom), they are only approximations of the real browser behavior. Jest is intended to be used for unit tests of your logic and your components rather than the DOM quirks. + +We recommend that you use a separate tool for browser end-to-end tests if you need them. They are beyond the scope of Create React App. + +### Filename Conventions + +Jest will look for test files with any of the following popular naming conventions: + +* Files with `.js` suffix in `__tests__` folders. +* Files with `.test.js` suffix. +* Files with `.spec.js` suffix. + +The `.test.js` / `.spec.js` files (or the `__tests__` folders) can be located at any depth under the `src` top level folder. + +We recommend to put the test files (or `__tests__` folders) next to the code they are testing so that relative imports appear shorter. For example, if `App.test.js` and `App.js` are in the same folder, the test just needs to `import App from './App'` instead of a long relative path. Colocation also helps find tests more quickly in larger projects. + +### Command Line Interface + +When you run `npm test`, Jest will launch in the watch mode. Every time you save a file, it will re-run the tests, just like `npm start` recompiles the code. + +The watcher includes an interactive command-line interface with the ability to run all tests, or focus on a search pattern. It is designed this way so that you can keep it open and enjoy fast re-runs. You can learn the commands from the “Watch Usage” note that the watcher prints after every run: + +![Jest watch mode](http://facebook.github.io/jest/img/blog/15-watch.gif) + +### Version Control Integration + +By default, when you run `npm test`, Jest will only run the tests related to files changed since the last commit. This is an optimization designed to make your tests runs fast regardless of how many tests you have. However it assumes that you don’t often commit the code that doesn’t pass the tests. + +Jest will always explicitly mention that it only ran tests related to the files changed since the last commit. You can also press `a` in the watch mode to force Jest to run all tests. + +Jest will always run all tests on a [continuous integration](#continuous-integration) server or if the project is not inside a Git or Mercurial repository. + +### Writing Tests + +To create tests, add `it()` (or `test()`) blocks with the name of the test and its code. You may optionally wrap them in `describe()` blocks for logical grouping but this is neither required nor recommended. + +Jest provides a built-in `expect()` global function for making assertions. A basic test could look like this: + +```js +import sum from './sum'; + +it('sums numbers', () => { + expect(sum(1, 2)).toEqual(3); + expect(sum(2, 2)).toEqual(4); +}); +``` + +All `expect()` matchers supported by Jest are [extensively documented here](http://facebook.github.io/jest/docs/expect.html).
+You can also use [`jest.fn()` and `expect(fn).toBeCalled()`](http://facebook.github.io/jest/docs/expect.html#tohavebeencalled) to create “spies” or mock functions. + +### Testing Components + +There is a broad spectrum of component testing techniques. They range from a “smoke test” verifying that a component renders without throwing, to shallow rendering and testing some of the output, to full rendering and testing component lifecycle and state changes. + +Different projects choose different testing tradeoffs based on how often components change, and how much logic they contain. If you haven’t decided on a testing strategy yet, we recommend that you start with creating simple smoke tests for your components: + +```js +import React from 'react'; +import ReactDOM from 'react-dom'; +import App from './App'; + +it('renders without crashing', () => { + const div = document.createElement('div'); + ReactDOM.render(, div); +}); +``` + +This test mounts a component and makes sure that it didn’t throw during rendering. Tests like this provide a lot value with very little effort so they are great as a starting point, and this is the test you will find in `src/App.test.js`. + +When you encounter bugs caused by changing components, you will gain a deeper insight into which parts of them are worth testing in your application. This might be a good time to introduce more specific tests asserting specific expected output or behavior. + +If you’d like to test components in isolation from the child components they render, we recommend using [`shallow()` rendering API](http://airbnb.io/enzyme/docs/api/shallow.html) from [Enzyme](http://airbnb.io/enzyme/). You can write a smoke test with it too: + +```sh +npm install --save-dev enzyme react-addons-test-utils +``` + +```js +import React from 'react'; +import { shallow } from 'enzyme'; +import App from './App'; + +it('renders without crashing', () => { + shallow(); +}); +``` + +Unlike the previous smoke test using `ReactDOM.render()`, this test only renders `` and doesn’t go deeper. For example, even if `` itself renders a ` + + + ); +} \ No newline at end of file diff --git a/src/UMap.js b/src/UMap.js new file mode 100644 index 0000000..8db9dc6 --- /dev/null +++ b/src/UMap.js @@ -0,0 +1,170 @@ +import React, {Component, useEffect, useRef, useState} from 'react'; +import SearchIcon from '@mui/icons-material/Search'; +import {MapContainer, TileLayer, Marker, Popup, useMap} from 'react-leaflet'; +import {useMapEvents} from 'react-leaflet/hooks'; +import {post} from './Networking'; +import {Autocomplete, CircularProgress, Sheet} from "@mui/joy"; +import SimulateClick from "./SimulateClick"; + +const AppleParkLoc=[37.334835049999995,-122.01139165956805]; + +class Markers extends Component { + constructor(props) { + super(props); + this.state = {markers: [], candMarkers: []}; + } + + render() { + const mks=this.state.markers.map((p, i) => ( + Generated + by Markers() + )); + const cmks=this.state.candMarkers.map((p, i) => ( + Generated + by Markers() + )); + return mks.concat(cmks); + } + + addMarker(lat, lng) { + this.setState((prev) => ({ + markers: [...prev.markers, [lat, lng]], candMarkers: prev.candMarkers, + })); + this.getFocus(); + } + + addCandMarker(lat, lng) { + this.setState((prev) => ({ + candMarkers: [...prev.candMarkers, [lat, lng]], + markers: prev.markers, + })); + this.getFocus(); + } + + clearMarkers() { + this.setState((prev) => ({markers: [], candMarkers: prev.candMarkers})); + this.getFocus(); + } + + clearCandMarkers(){ + this.setState((prev) => ({markers: prev.markers, candMarkers: []})); + this.getFocus(); + } + + getFocus() { + let currentFocus=[]; + if (this.state.candMarkers.length) { + currentFocus=this.state.candMarkers.at(-1); + } else if (this.state.markers.length) { + currentFocus=this.state.markers.at(-1); + } else { + currentFocus=AppleParkLoc; + } + this.props.focusUpdater(currentFocus); + } +} + +function MapClickHandler({mks}) { + const map = useMapEvents({ + click: (e) => { + map.locate(); + const lat = e.latlng.lat, lng = e.latlng.lng; + console.info(`Clicking on ${lat} ${lng}`); + mks.current.addMarker(lat, lng); + post('click', [lat, lng]); + }, + // TODO + locationfound: (location) => { + console.info('location found:', location); + }, + }); + return null; +} + +const LocationSearch = ({mks}) => { + const [query, setQuery] = useState(''); + const [loading, setLoading] = useState(false); + const [suggestedLocations, setSuggestedLocations] = useState([]); + const [controller, setController] = useState(new AbortController()); + + useEffect(() => { + return () => controller.abort(); + }, [query]); + + const handleSearch = async (e, v) => { + const newController = new AbortController(); + setController(newController); + setLoading(true); + setQuery(v); + try { + // setSuggestedLocations([]); + if (v.trim() === '') { + setLoading(false); + return; + } + const response = await fetch( + `https://nominatim.openstreetmap.org/search?format=json&q=${v}`, + {signal: newController.signal} + ); + if (response.ok) { + response.json().then((data) => { + if (data.length > 0) { + // const {lat, lon} = data[0]; + mks.current.clearCandMarkers(); + const res = []; + data.forEach((v, i, a) => { + res.push(v['display_name']); + mks.current.addCandMarker(parseFloat(v['lat']), parseFloat(v['lon'])); + }); + setSuggestedLocations(res); + } else { + console.warn(`No result on ${v}`) + } + }) + } else { + console.error('Nominatim search failed.'); + } + setLoading(false); + } catch (error) { + console.error('Error during Nominatim search:', error); + } + }; + + return } + placeholder={'Find a location...'} onInputChange={handleSearch} + options={suggestedLocations} isOptionEqualToValue={(option, value) => option.value === value.value} endDecorator={ + loading ? ( + + ) : null + }/>; +}; + +function ChangeView({center,zoom}){ + const map=useMap(); + map.setView(center,zoom); +} + +export default function UMap() { + const markersRef = useRef(null); + const [focus, setFocus]=useState([37.334835049999995,-122.01139165956805]); + const zoom=13; + const sf=(a)=>{setFocus(a);console.log(`triggered focus update, new focus is ${focus}`);}; + return ( + + + + + + + + + + + + + ); +}; diff --git a/src/index.css b/src/index.css new file mode 100644 index 0000000..b4cc725 --- /dev/null +++ b/src/index.css @@ -0,0 +1,5 @@ +body { + margin: 0; + padding: 0; + font-family: sans-serif; +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..54c5ef1 --- /dev/null +++ b/src/index.js @@ -0,0 +1,9 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import App from './App'; +import './index.css'; + +ReactDOM.render( + , + document.getElementById('root') +); diff --git a/src/logo.svg b/src/logo.svg new file mode 100644 index 0000000..6b60c10 --- /dev/null +++ b/src/logo.svg @@ -0,0 +1,7 @@ + + + + + + +