Skip to content

Commit

Permalink
feat: don't select city automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Massolari committed Nov 6, 2024
1 parent 86a97aa commit a079aa6
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions 2024-09-26-typescript-effect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const getRequest = (url: string): Effect.Effect<HttpClientResponse.HttpClientRes
Effect.provide(FetchHttpClient.layer),
);

const getCities = (search: string): Effect.Effect<Option.Option<void>, never, never> => {
const getCities = (search: string): Effect.Effect<Option.Option<void | Option.Option<void>>, never, never> => {
Option.map(citiesElement, (c) => (c.innerHTML = ""));

return pipe(
Expand Down Expand Up @@ -99,20 +99,14 @@ const getCity = (city: string): Effect.Effect<readonly CityResponse[], never, ne
Effect.scoped,
);

const renderCitySuggestions = (cities: readonly CityResponse[]): void => {
const renderCitySuggestions = (cities: readonly CityResponse[]): void | Option.Option<void> =>
// If there are multiple cities, populate the suggestions
if (cities.length > 1) {
populateSuggestions(cities);
return;
}

// We didn't get into the if statement above, so we have only one city or none
// Let's try to get the first city
// Otherwise, show a message that the city was not found
pipe(
Array.head(cities),
Option.match({
onSome: selectCity,
onNone: () => {
cities,
Array.match({
onNonEmpty: populateSuggestions,
onEmpty: () => {
const search = Option.match(cityElement, {
onSome: (cityEl) => cityEl.value,
onNone: () => "searched",
Expand All @@ -126,7 +120,7 @@ const renderCitySuggestions = (cities: readonly CityResponse[]): void => {
},
}),
);
};


const populateSuggestions = (results: readonly CityResponse[]): Option.Option<void> =>
Option.map(citiesElement, (citiesEl) =>
Expand Down

0 comments on commit a079aa6

Please sign in to comment.