Skip to content

Commit

Permalink
Display country name in country page
Browse files Browse the repository at this point in the history
  • Loading branch information
YoruNoHikage authored and engleek committed Mar 14, 2023
1 parent 2e90670 commit e7b322c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/routes/country.$code.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ import { json, redirect } from '@remix-run/node';
import { Link, useLoaderData } from '@remix-run/react';

import { db } from '../utils/db.server';
import countryNames from '../assets/countries.json';

export const loader = async ({ params }) => {
if (!params.code) {
return redirect('/countries');
}

const countryCode = params.code.toUpperCase();

// using remix-i18n ?
// let locale = await i18next.getLocale(request);

// fetch country data and use right locale

const cities =
await db.$queryRaw`select city as name, count(e.id)::int from indieco.location l left join indieco.entity e on l.id = e.location_id where country_code = ${params.code.toUpperCase()} group by city order by count desc limit 10`;
await db.$queryRaw`select city as name, count(e.id)::int from indieco.location l left join indieco.entity e on l.id = e.location_id where country_code = ${countryCode} group by city order by count desc limit 10`;

// country does not exist
if (cities.length === 0) {
Expand All @@ -39,7 +42,8 @@ export const loader = async ({ params }) => {

const data = {
country: {
name: params.code,
code: countryCode,
name: countryNames[countryCode],
cities,
},
};
Expand Down Expand Up @@ -68,8 +72,9 @@ const CountriesPage = () => {
columns={{ base: 4, sm: 5, md: 6 }}
gap={{ base: '5', md: '6' }}
>
{country.cities.map(({ name, count }) => (
{country.cities.map(({ code, name, count }) => (
<LinkBox
key={code}
px={{ base: '4', md: '6' }}
py={{ base: '5', md: '6' }}
bg="bg-surface"
Expand Down

0 comments on commit e7b322c

Please sign in to comment.