Skip to content

Commit

Permalink
feat: remove wifi or workspace conditional (#26)
Browse files Browse the repository at this point in the history
* bugfix: handle variable number of listing detail rows

Signed-off-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>

* feat: add comment to

Signed-off-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>

* feat: remove wifi or workspace conditional

Signed-off-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>
  • Loading branch information
Patrick-Erichsen authored Nov 7, 2021
1 parent 132944f commit 02c1ab5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 69 deletions.
2 changes: 1 addition & 1 deletion assets/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Offie - Airbnb Wifi Reviews",
"description": "View Wifi and workspace info from the Airbnb search results page.",
"manifest_version": 3,
"version": "0.0.7",
"version": "0.0.8",
"icons": {
"16": "img/offie-logo-16.png",
"48": "img/offie-logo-48.png",
Expand Down
14 changes: 3 additions & 11 deletions src/content/App.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
import { useState } from 'react';
import { useUrlChangeChrome } from './hooks/useUrlChangeChrome';
import { OffiePortals } from './components/OffiePortals';
import { hasWifiOrWorkspaceFilter, isHomesSearchPage } from './utils';
import { isHomesSearchPage } from './utils';
import './App.css';

export const App = (): JSX.Element | null => {
const [isVisible, setIsVisible] = useState<boolean>(false);

useUrlChangeChrome((newUrl) => {
/**
* If a user is not on the search page, ignore the update
* Only render if on the homes search page
*/
if (isHomesSearchPage(newUrl)) {
const newIsVisible = hasWifiOrWorkspaceFilter(newUrl);

setIsVisible(newIsVisible);
}
setIsVisible(isHomesSearchPage(newUrl));
});

/**
* Only display our portals if the `Wifi` or
* `Dedicated workspace` filters are active
*/
if (!isVisible) {
return null;
}
Expand Down
20 changes: 0 additions & 20 deletions src/content/utils/__tests__/airbnb.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,6 @@ describe('airbnb.ts', () => {
});
});

describe('hasWifiOrWorkspaceFilter()', () => {
it('returns true is the url string has the wifi filter key', () => {
const mockUrl = `https://www.airbnb.com/s/Downtown--Honolulu--HI--United-States/homes?amenities%5B%5D=${airbnb.WIFI_FILTER_KEY_NUM}`;

expect(airbnb.hasWifiOrWorkspaceFilter(mockUrl)).toBe(true);
});

it('returns true is the url string has the dedicated workspace filter key', () => {
const mockUrl = `https://www.airbnb.com/s/Downtown--Honolulu--HI--United-States/homes?amenities%5B%5D=${airbnb.DEDICATED_WORKSPACE_FILTER_KEY_NUM}`;

expect(airbnb.hasWifiOrWorkspaceFilter(mockUrl)).toBe(true);
});

it('returns false is the url string does not have the dedicated workspace or wifi filter keys', () => {
const mockUrl = `https://www.airbnb.com/s/Downtown--Honolulu--HI--United-States/homes`;

expect(airbnb.hasWifiOrWorkspaceFilter(mockUrl)).toBe(false);
});
});

describe('isHomesSearchPage()', () => {
it('returns false if not a homes search page', () => {
expect(
Expand Down
40 changes: 3 additions & 37 deletions src/content/utils/airbnb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as qs from 'qs';
import { rollbar } from '../../utils/rollbar';
import { getParsedUrlSearch } from './misc';

export interface AirbnbFilterKeyMap {
[key: number]: string;
Expand Down Expand Up @@ -29,6 +28,8 @@ export const WIFI_FILTER_KEY_NUM = 4;

export const DEDICATED_WORKSPACE_FILTER_KEY_NUM = 47;

export const HOMES_SEARCH_ROUTE = '/homes';

/**
* What is `kg_and_tags`? E.g. `Beachfront`, `Ski-in/ski-out` filters
*/
Expand Down Expand Up @@ -266,43 +267,8 @@ export const getMappedSearchFilters = (
}, {});
};

/**
* Check if an Airbnb search URL contains a filter for `Wifi` or
* `Dedicated workspaces`.
*/
export const hasWifiOrWorkspaceFilter = (urlStr: string): boolean => {
const search = getParsedUrlSearch(urlStr);
const filters = getMappedSearchFilters(search);

const { amenities } = filters;

// If a user has not applied any filters yet, return
if (!amenities) {
return false;
}

// We expect the amenities URL param to be an array type, so log an error
// if it is not an array
if (!Array.isArray(amenities)) {
rollbar.warning(
`Expected the amenities key to an array, but found: ${typeof amenities}`
);

return false;
}

const hasWifiFilter = amenities.includes(
FILTERABLE_AMENITY_ID_TO_STR[WIFI_FILTER_KEY_NUM]
);
const hasDedicatedWorkspaceFilter = amenities.includes(
FILTERABLE_AMENITY_ID_TO_STR[DEDICATED_WORKSPACE_FILTER_KEY_NUM]
);

return hasWifiFilter || hasDedicatedWorkspaceFilter;
};

export const isHomesSearchPage = (url: string): boolean => {
const { pathname } = new URL(url);

return pathname.includes('/homes');
return pathname.includes(HOMES_SEARCH_ROUTE);
};

0 comments on commit 02c1ab5

Please # to comment.