Skip to content

Commit

Permalink
Various bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sibbl committed Jul 1, 2023
1 parent 9abf303 commit d48d39d
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 27 deletions.
8 changes: 4 additions & 4 deletions config.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion scraper/ImmonetScraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
58 changes: 43 additions & 15 deletions src/actions/flat-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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 {
Expand All @@ -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());
}
};
2 changes: 1 addition & 1 deletion src/components/date-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] });
Expand Down
2 changes: 0 additions & 2 deletions src/components/flat-map/mapnificient/mapnificient-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -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]);
Expand Down
31 changes: 30 additions & 1 deletion src/reducers/flat-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,7 +25,8 @@ const initialState = {
visibleFlatIds: null,
selectedFlatId: null,
previewedFlatId: null,
filters: null
filters: null,
allFlatsLoaded: false
};

const getVisibleFlatIds = ({ flats, filters }) => {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/services/WohnungScraperApi.js
Original file line number Diff line number Diff line change
@@ -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;
};

Expand Down
2 changes: 1 addition & 1 deletion src/services/date-utils.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit d48d39d

Please sign in to comment.