From d48d39dc878dcb278e556c2864fcb7074105d956 Mon Sep 17 00:00:00 2001 From: Sebastian Schubotz Date: Sat, 1 Jul 2023 16:55:17 +0200 Subject: [PATCH] Various bugfixes --- config.template.js | 8 +-- scraper/ImmonetScraper.js | 2 +- src/actions/flat-actions.js | 58 ++++++++++++++----- src/components/date-slider.js | 2 +- .../mapnificient/mapnificient-layer.js | 2 - src/reducers/flat-reducer.js | 31 +++++++++- src/services/WohnungScraperApi.js | 4 +- src/services/date-utils.js | 2 +- 8 files changed, 82 insertions(+), 27 deletions(-) diff --git a/config.template.js b/config.template.js index 1ec87b6..836f38f 100644 --- a/config.template.js +++ b/config.template.js @@ -111,13 +111,13 @@ module.exports = async () => { }, free_from: { min: "now", - max: DateTime.local() + max: DateTime.utc() .startOf("month") .plus({ months: 6 }) .toISODate() }, age: { - min: DateTime.local() + min: DateTime.utc() .startOf("month") .plus({ months: -6 }) .toISODate(), @@ -142,13 +142,13 @@ module.exports = async () => { }, free_from: { min: "now", - max: DateTime.local() + max: DateTime.utc() .startOf("month") .plus({ months: 3 }) .toISODate() }, age: { - min: DateTime.local() + min: DateTime.utc() .startOf("month") .plus({ months: -3 }) .toISODate(), diff --git a/scraper/ImmonetScraper.js b/scraper/ImmonetScraper.js index c61427c..b6062b8 100644 --- a/scraper/ImmonetScraper.js +++ b/scraper/ImmonetScraper.js @@ -188,7 +188,7 @@ module.exports = class ImmonetScraper extends AbstractScraper { }); result.data.features = features; } catch (ex) { - console.log("CATCHED error while scraping item", this.id, url, ex); + console.log("CAUGHT error while scraping item", this.id, url, ex); result.gone = true; if (result.removed == null) { result.removed = new Date(); diff --git a/src/actions/flat-actions.js b/src/actions/flat-actions.js index 88fbe01..43393ab 100644 --- a/src/actions/flat-actions.js +++ b/src/actions/flat-actions.js @@ -4,6 +4,10 @@ export const GET_FLATS = "GET_FLATS"; export const GET_FLATS_SUCCESS = "GET_FLATS_SUCCESS"; export const GET_FLATS_FAILURE = "GET_FLATS_FAILURE"; +export const GET_ALL_FLATS = "GET_ALL_FLATS"; +export const GET_ALL_FLATS_SUCCESS = "GET_ALL_FLATS_SUCCESS"; +export const GET_ALL_FLATS_FAILURE = "GET_ALL_FLATS_FAILURE"; + export const SET_PREVIEWED_FLAT = "SET_PREVIEWED_FLAT"; export const UNSET_PREVIEWED_FLAT = "UNSET_PREVIEWED_FLAT"; @@ -13,7 +17,7 @@ export const UNSET_SELECTED_FLAT = "UNSET_SELECTED_FLAT"; export const SET_FLAT_FILTERS = "SET_FLAT_FILTERS"; export const getFlats = () => { - return async dispatch => { + return async (dispatch) => { dispatch({ type: GET_FLATS }); try { @@ -27,22 +31,46 @@ export const getFlats = () => { }; }; -export const setPreviewedFlat = ({ flatId }) => dispatch => { - if (flatId != null) { - dispatch({ type: SET_PREVIEWED_FLAT, flatId }); - } else { - dispatch({ type: UNSET_PREVIEWED_FLAT }); - } -}; +export const getAllFlats = () => { + return async (dispatch) => { + dispatch({ type: GET_ALL_FLATS }); -export const setSelectedFlat = ({ flatId }) => dispatch => { - if (flatId != null) { - dispatch({ type: SET_SELECTED_FLAT, flatId }); - } else { - dispatch({ type: UNSET_SELECTED_FLAT }); - } + try { + const flats = await getFlatsFromApi({ all: true }); + + dispatch({ type: GET_ALL_FLATS_SUCCESS, flats }); + } catch (error) { + console.error(error); + dispatch({ type: GET_ALL_FLATS_FAILURE, error }); + } + }; }; -export const setFlatFilters = filters => dispatch => { +export const setPreviewedFlat = + ({ flatId }) => + (dispatch) => { + if (flatId != null) { + dispatch({ type: SET_PREVIEWED_FLAT, flatId }); + } else { + dispatch({ type: UNSET_PREVIEWED_FLAT }); + } + }; + +export const setSelectedFlat = + ({ flatId }) => + (dispatch) => { + if (flatId != null) { + dispatch({ type: SET_SELECTED_FLAT, flatId }); + } else { + dispatch({ type: UNSET_SELECTED_FLAT }); + } + }; + +export const setFlatFilters = (filters) => (dispatch, getState) => { dispatch({ type: SET_FLAT_FILTERS, filters }); + + const state = getState(); + if (filters.hideInactive === false && state.flat.allFlatsLoaded === false) { + dispatch(getAllFlats()); + } }; diff --git a/src/components/date-slider.js b/src/components/date-slider.js index df311cf..afcbe8e 100644 --- a/src/components/date-slider.js +++ b/src/components/date-slider.js @@ -24,7 +24,7 @@ const DateSlider = ({ const isDateEqual = (date1, date2) => date1.hasSame(date2, "day"); const isDateToday = date => - isDateEqual(date, DateTime.local().startOf("day")); + isDateEqual(date, DateTime.utc().startOf("day")); const onChangeMapped = value => onChange({ min: mapping[value.min], max: mapping[value.max] }); diff --git a/src/components/flat-map/mapnificient/mapnificient-layer.js b/src/components/flat-map/mapnificient/mapnificient-layer.js index f09e7e1..e6ac63a 100644 --- a/src/components/flat-map/mapnificient/mapnificient-layer.js +++ b/src/components/flat-map/mapnificient/mapnificient-layer.js @@ -15,7 +15,6 @@ export default function MapnificientLayer({ const mapnificientPositionRef = useRef(null); useEffect(() => { - console.log("mapnificent add"); const mapnificent = new Mapnificent(map, config, { dataPath: `https://cdn.jsdelivr.net/gh/mapnificent/mapnificent_cities/${config.cityid}/`, baseurl: "./lib/mapnificient/" @@ -25,7 +24,6 @@ export default function MapnificientLayer({ map.on("viewreset", mapnificent.redraw); map.on("zoomend", mapnificent.redraw); return () => { - console.log("mapnificent remove"); mapnificent.destroy(); }; }, [map, config]); diff --git a/src/reducers/flat-reducer.js b/src/reducers/flat-reducer.js index d2834c5..13548f2 100644 --- a/src/reducers/flat-reducer.js +++ b/src/reducers/flat-reducer.js @@ -3,6 +3,9 @@ import { GET_FLATS, GET_FLATS_SUCCESS, GET_FLATS_FAILURE, + GET_ALL_FLATS, + GET_ALL_FLATS_SUCCESS, + GET_ALL_FLATS_FAILURE, SET_PREVIEWED_FLAT, UNSET_PREVIEWED_FLAT, SET_SELECTED_FLAT, @@ -22,7 +25,8 @@ const initialState = { visibleFlatIds: null, selectedFlatId: null, previewedFlatId: null, - filters: null + filters: null, + allFlatsLoaded: false }; const getVisibleFlatIds = ({ flats, filters }) => { @@ -32,6 +36,10 @@ const getVisibleFlatIds = ({ flats, filters }) => { return Object.entries(flats) .filter(([, flat]) => { + if(!flat.latitude || !flat.longitude) { + return false; + } + if (filters.showOnlyFavs && !flat.favorite) { return false; } @@ -100,6 +108,27 @@ export const flatReducer = (state = initialState, action) => { draftState.error = action.error; return; + case GET_ALL_FLATS: + draftState.isWorking = true; + draftState.error = null; + return; + + case GET_ALL_FLATS_SUCCESS: + draftState.isWorking = false; + draftState.error = null; + draftState.flats = action.flats; + draftState.allFlatsLoaded = true; + draftState.visibleFlatIds = getVisibleFlatIds({ + flats: action.flats, + filters: state.filters + }); + return; + + case GET_ALL_FLATS_FAILURE: + draftState.isWorking = false; + draftState.error = action.error; + return; + case SET_PREVIEWED_FLAT: draftState.previewedFlatId = action.flatId; return; diff --git a/src/services/WohnungScraperApi.js b/src/services/WohnungScraperApi.js index 4526fc1..501963e 100644 --- a/src/services/WohnungScraperApi.js +++ b/src/services/WohnungScraperApi.js @@ -1,7 +1,7 @@ import axios from "axios"; -export const getFlats = async () => { - const { data } = await axios.get("/data"); +export const getFlats = async ({ all } = {}) => { + const { data } = await axios.get("/data", { params: { all } }); return data; }; diff --git a/src/services/date-utils.js b/src/services/date-utils.js index 8a81762..1546d18 100644 --- a/src/services/date-utils.js +++ b/src/services/date-utils.js @@ -1,4 +1,4 @@ import { DateTime } from "luxon"; export const getDateTime = date => - date === "now" ? DateTime.local().startOf("day") : DateTime.fromISO(date); + date === "now" ? DateTime.utc().startOf("day") : DateTime.fromISO(date);