Skip to content

Commit

Permalink
Refactored places into bookshops
Browse files Browse the repository at this point in the history
  • Loading branch information
silversonicaxel committed Sep 16, 2024
1 parent 0200c6b commit eea9674
Show file tree
Hide file tree
Showing 27 changed files with 193 additions and 183 deletions.
File renamed without changes.
18 changes: 9 additions & 9 deletions locales/en/common.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"title": "unknown art",
"description": "unknown art is the club that will introduce you to arty and independent bookstores, all over the world.",
"description": "unknown art is the club that will introduce you to arty and independent bookshops, all over the world.",
"menu" : {
"home": "home",
"places": "places",
"place": "place"
"bookshops": "bookshops",
"bookshop": "bookshop"
},
"language" : {
"it": "italian",
Expand All @@ -20,8 +20,8 @@
"page": "page"
},
"search": {
"title": "search places",
"description": "filter the list of places",
"title": "search bookshops",
"description": "filter the list of bookshops",
"field": {
"total": {
"label": "total"
Expand All @@ -47,18 +47,18 @@
"action": {
"dialog": {
"title": "search",
"label": "open the dialog search of places"
"label": "open the dialog search of bookshops"
},
"close": {
"label": "close search places dialog"
"label": "close search bookshops dialog"
},
"submit": {
"title": "search",
"label": "submit the search of places"
"label": "submit the search of bookshops"
},
"reset": {
"title": "reset",
"label": "reset the search of places"
"label": "reset the search of bookshops"
}
}
},
Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions locales/it/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "unknown art è il club che ti farà conoscere librerie artistiche ed indipendenti, in tutto il mondo.",
"menu": {
"home": "home",
"places": "posti",
"place": "posto"
"bookshops": "librerie",
"bookshop": "libreria"
},
"language": {
"it": "italiano",
Expand All @@ -20,8 +20,8 @@
"page": "pagina"
},
"search": {
"title": "ricerca posti",
"description": "filtra la lista di posti",
"title": "ricerca librerie",
"description": "filtra la lista di librerie",
"field": {
"total": {
"label": "totale"
Expand All @@ -47,18 +47,18 @@
"action": {
"dialog": {
"title": "cerca",
"label": "apri la finestra di ricerca di posti"
"label": "apri la finestra di ricerca di librerie"
},
"close": {
"label": "chiusi la finestra di ricerca di posti"
"label": "chiusi la finestra di ricerca di librerie"
},
"submit": {
"title": "cerca",
"label": "effettua la ricerca di posti"
"label": "effettua la ricerca di librerie"
},
"reset": {
"title": "resetta",
"label": "resetta la ricerca di posti"
"label": "resetta la ricerca di librerie"
}
}
},
Expand Down
24 changes: 12 additions & 12 deletions src/api/place/index.ts → src/api/bookshop/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { clientPromise } from 'helpers/config/mongodb'
import type { Bookshop } from 'src/types/bookshop'
import type { ApiQuery } from 'types/api'
import type { Place } from 'types/place'
import type { SearchPlacesApi } from 'types/search'
import type { SearchBookshopsApi } from 'types/search'


const getFindParamsFilter = (search: string) => {
const searchData = JSON.parse(search)

const searchFilter: SearchPlacesApi = {}
const searchFilter: SearchBookshopsApi = {}
if (searchData.name) {
searchFilter.name = { $regex: searchData.name, $options: 'si' }
}
Expand Down Expand Up @@ -38,41 +38,41 @@ const getFindParams = (query: ApiQuery = {}) => {
return { findFilter, findOptions }
}

export const getPlacesList = async (query: ApiQuery = {}): Promise<Place[]> => {
export const getBookshopsList = async (query: ApiQuery = {}): Promise<Bookshop[]> => {
const { findFilter, findOptions } = getFindParams(query)

const mongoClient = await clientPromise
const places = await mongoClient
const bookshops = await mongoClient
.db('ua-db')
.collection('ua-places')
.find(findFilter, findOptions)
.collation({ locale: 'en' })
.sort({ name: 1 })
.toArray()

return JSON.parse(JSON.stringify(places))
return JSON.parse(JSON.stringify(bookshops))
}

export const getPlace = async (id: string): Promise<Place> => {
export const getBookshop = async (id: string): Promise<Bookshop> => {
const mongoClient = await clientPromise
const place = await mongoClient
const bookshop = await mongoClient
.db('ua-db')
.collection('ua-places')
.findOne({ id })

return JSON.parse(JSON.stringify(place))
return JSON.parse(JSON.stringify(bookshop))
}

export const getTotalPlaces = async (query: ApiQuery = {}): Promise<number> => {
export const getTotalBookshops = async (query: ApiQuery = {}): Promise<number> => {
const { findFilter } = getFindParams(query)

const mongoClient = await clientPromise
const places = await mongoClient
const bookshops = await mongoClient
.db('ua-db')
.collection('ua-places')
.find(findFilter)
.collation({ locale: 'en' })
.toArray()

return places.length
return bookshops.length
}
2 changes: 1 addition & 1 deletion src/api/country/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getCountryCodesList = async (): Promise<CountryCode> => {
return isos === null ? {} : isos
}

export const getPlacesCountryCodesList = async (): Promise<CountryCode> => {
export const getBookshopsCountryCodesList = async (): Promise<CountryCode> => {
const mongoClient = await clientPromise

const relevantIsos = await mongoClient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.uaplace {
.uabookshop {
white-space: break-spaces;
word-wrap: break-word;
}

.uaplace_section {
.uabookshop_section {
margin-bottom: var(--spacing-group);
position: relative;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import { useParams } from 'next/navigation'
import type { Metadata } from 'next/types'
import { useCallback } from 'react'

import { ErrorContent } from 'src/components/error-content'
import { useTranslationClient } from 'helpers/hooks/useTranslationClient'
import { ErrorContent } from 'src/components/error-content'
import { ComponentErrorParams } from 'types/component'
import { I18nLocale } from 'types/i18n'


type PlacesErrorProps = ComponentErrorParams
type BookshopErrorProps = ComponentErrorParams

export const metadata: Metadata = {
title: 'unknown art',
}

export default function PlacesError({ reset }: PlacesErrorProps) {
export default function BookshopError({ reset }: BookshopErrorProps) {
const params = useParams()
const locale = params.locale as I18nLocale

const { t } = useTranslationClient({ locale, namespace: 'common' })
const tPage = t('menu.places')
const tPage = t('menu.bookshop')

const onReset = useCallback(() => {
reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import { useParams } from 'next/navigation'

import { Loading } from 'src/components/loading'
import { useTranslationClient } from 'helpers/hooks/useTranslationClient'
import { Loading } from 'src/components/loading'
import { I18nLocale } from 'types/i18n'


export default function PlacesLoading() {
export default function BookshopsLoading() {
const params = useParams()
const locale = params.locale as I18nLocale

const { t } = useTranslationClient({ locale, namespace: 'common' })

return <Loading text={t('menu.place')} />
return <Loading text={t('menu.bookshop')} />
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,108 +3,108 @@ import type { fetchedMeta as FetchedMetadata } from 'fetch-meta-tags'
import type { Metadata } from 'next'
import { notFound } from 'next/navigation'

import styles from './place.module.css'
import styles from './bookshop.module.css'

import { getPlace } from 'api/place'
import { SafeImage } from 'src/components/safe-image'
import { locales_codes } from 'helpers/config/i18n'
import { meta, META_SITE_BASE_URL } from 'helpers/config/meta'
import { getTranslationServer } from 'helpers/utils/getTranslationServer'
import { isImageSecure } from 'helpers/utils/isImageSecure'
import { getBookshop } from 'src/api/bookshop'
import { SafeImage } from 'src/components/safe-image'
import type { ComponentParams } from 'types/component'
import { I18nLocale } from 'types/i18n'


type PlacePageProps = {
type BookshopPageProps = {
params: {
placeId: string
bookshopId: string
}
} & ComponentParams

type PlaceMeta = FetchedMetadata | null
type BookshopMeta = FetchedMetadata | null

export async function generateMetadata(
{ params: { placeId, locale } }: PlacePageProps
{ params: { bookshopId, locale } }: BookshopPageProps
): Promise<Metadata | void> {
const { t } = await getTranslationServer({ locale, namespace: 'common' })
const place = await getPlace(placeId)
if (place === null) {
const bookshop = await getBookshop(bookshopId)
if (bookshop === null) {
return
}

return {
title: `${meta.siteName} _ ${t('menu.place')} _ ${place.name}`,
title: `${meta.siteName} _ ${t('menu.bookshop')} _ ${bookshop.name}`,
openGraph: {
title: `${meta.siteName} - ${t('menu.places')}`,
title: `${meta.siteName} - ${t('menu.bookshops')}`,
description: t('description'),
url: `${META_SITE_BASE_URL}${locale}/places/${place.id}`,
url: `${META_SITE_BASE_URL}${locale}/bookshops/${bookshop.id}`,
siteName: meta.siteName,
locale: locales_codes[locale as I18nLocale],
type: 'website',
}
}
}

export default async function PlacePage(
{ params: { placeId, locale } }: PlacePageProps
export default async function BookshopPage(
{ params: { bookshopId, locale } }: BookshopPageProps
) {
const { t } = await getTranslationServer({ locale, namespace: 'places' })
const { t } = await getTranslationServer({ locale, namespace: 'bookshops' })

const place = await getPlace(placeId)
if (place === null) {
const bookshop = await getBookshop(bookshopId)
if (bookshop === null) {
notFound()
}

let placeMeta: PlaceMeta
let bookshopMeta: BookshopMeta
try {
placeMeta = place.site ? await fetchedMeta(place.site) : null
bookshopMeta = bookshop.site ? await fetchedMeta(bookshop.site) : null
} catch {
placeMeta = null
bookshopMeta = null
}

return (
<>
<h1>{place.name}</h1>
<article className={styles.uaplace}>
<section className={styles.uaplace_section}>
<h1>{bookshop.name}</h1>
<article className={styles.uabookshop}>
<section className={styles.uabookshop_section}>
<h4>{t('form.address')}</h4>

<a
href={place.address_url ? place.address_url : `https://www.google.com/maps/place/${place.address}`}
href={bookshop.address_url ? bookshop.address_url : `https://www.google.com/maps/place/${bookshop.address}`}
target="_blank"
rel="noreferrer"
>
{place.address}
{bookshop.address}
</a>
</section>

{place.site && (
<section className={styles.uaplace_section}>
{bookshop.site && (
<section className={styles.uabookshop_section}>
<h4>{t('form.website')}</h4>
<a
href={place.site}
href={bookshop.site}
target="_blank"
rel="noreferrer"
>
{place.site}
{bookshop.site}
</a>
</section>
)}

{placeMeta?.image && (
<section className={styles.uaplace_section}>
{bookshopMeta?.image && (
<section className={styles.uabookshop_section}>
<h4>{t('form.description')}</h4>
<p>{placeMeta.description}</p>
<p>{bookshopMeta.description}</p>
</section>
)}

{placeMeta?.image && isImageSecure(placeMeta.image) && (
<section className={styles.uaplace_section}>
{bookshopMeta?.image && isImageSecure(bookshopMeta.image) && (
<section className={styles.uabookshop_section}>
<h4>{t('form.image')}</h4>
<SafeImage
src={placeMeta.image}
alt={place.name}
aria-label={place.name}
src={bookshopMeta.image}
alt={bookshop.name}
aria-label={bookshop.name}
/>
</section>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.uaplaces {
.uabookshops {
margin-bottom: var(--spacing-element);
}
Loading

0 comments on commit eea9674

Please sign in to comment.