Skip to content

Commit

Permalink
worked on customization issue
Browse files Browse the repository at this point in the history
  • Loading branch information
OchiengPaul442 committed Nov 21, 2023
1 parent 93eea02 commit d09471f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,28 @@ const LocationsContentComponent = ({ selectedLocations }) => {
};

const handleLocationSelect = (item) => {
unSelectedLocations.includes(item)
? setUnSelectedLocations(unSelectedLocations.filter((location) => location._id !== item._id))
: null;
locationArray.includes(item)
? setLocationArray(locationArray.filter((location) => location._id !== item._id))
: setLocationArray((locations) => [...locations, item]);
const unSelectedIndex = unSelectedLocations.findIndex((location) => location._id === item._id);
if (unSelectedIndex !== -1) {
setUnSelectedLocations(unSelectedLocations.filter((location) => location._id !== item._id));
}
const locationIndex = locationArray.findIndex((location) => location._id === item._id);
if (locationIndex !== -1) {
setLocationArray(locationArray.filter((location) => location._id !== item._id));
} else {
const newLocationArray = [...locationArray, item];
setLocationArray(newLocationArray);
setDraggedLocations(newLocationArray);
}
setInputSelect(true);
setLocation('');
};

const removeLocation = (item) => {
setLocationArray(locationArray.filter((location) => location._id !== item._id));
const newLocationArray = locationArray.filter((location) => location._id !== item._id);
setLocationArray(newLocationArray);
setDraggedLocations(newLocationArray);
setUnSelectedLocations((locations) => [...locations, item]);
dispatch(setSelectedLocations(locationArray));
dispatch(setSelectedLocations(newLocationArray));
};

const onDragEnd = (result) => {
Expand Down Expand Up @@ -90,7 +98,7 @@ const LocationsContentComponent = ({ selectedLocations }) => {
while (unSelectedLocations.length < 8) {
const randomIndex = Math.floor(Math.random() * gridLocationsData.length);
const randomObject = gridLocationsData[randomIndex];
if (!unSelectedLocations.includes(randomObject)) {
if (!unSelectedLocations.find((location) => location._id === randomObject._id)) {
unSelectedLocations.push(randomObject);
}
}
Expand Down
3 changes: 2 additions & 1 deletion platform/src/common/components/Customise/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const CustomiseLocationsComponent = ({ toggleCustomise }) => {
});
const selectedLocations = useSelector((state) => state.grids.selectedLocations) || [];
const preferenceData = useSelector((state) => state.defaults.individual_preferences) || [];
const customisedLocations = preferenceData.length > 0 ? preferenceData[0].selected_sites : [];
const customisedLocations =
preferenceData.length > 0 ? preferenceData[0].selected_sites.slice(0, 4) : [];
const id = useSelector((state) => state.login.userInfo._id);
const chartData = useSelector((state) => state.chart);

Expand Down
2 changes: 1 addition & 1 deletion platform/src/common/components/Layout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Layout = ({ pageTitle = 'AirQo Analytics', children, topbarTitle, noBorder
? selected_sites.map((site) => site['_id'])
: chartData.chartSites;

await dispatch(setChartSites(chartSites));
await dispatch(setChartSites(chartSites.slice(0, 4)));
await dispatch(
setChartDataRange({
startDate: startDate || chartData.chartDataRange.startDate,
Expand Down
5 changes: 4 additions & 1 deletion platform/src/pages/_app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export default function App({ Component, ...rest }) {
const persistor = persistStore(store);

useEffect(() => {
if (process.env.NEXT_PUBLIC_ALLOW_DEV_TOOLS === 'staging') {
if (
process.env.NEXT_PUBLIC_ALLOW_DEV_TOOLS === 'staging' ||
process.env.NEXT_PUBLIC_ALLOW_DEV_TOOLS === 'production'
) {
return;
} else {
// Disable context menu (right click)
Expand Down

0 comments on commit d09471f

Please sign in to comment.