mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 07:25:48 +01:00
✨ Improvements to city selection in weather widget
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
ActionIcon,
|
ActionIcon,
|
||||||
|
Anchor,
|
||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
|
Center,
|
||||||
Group,
|
Group,
|
||||||
Loader,
|
Loader,
|
||||||
Modal,
|
Modal,
|
||||||
@@ -14,13 +16,14 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { useDisclosure } from '@mantine/hooks';
|
import { useDisclosure } from '@mantine/hooks';
|
||||||
import { IconClick, IconListSearch } from '@tabler/icons-react';
|
import { IconAlertTriangle, IconClick, IconListSearch } from '@tabler/icons-react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { City } from '~/server/api/routers/weather';
|
import { City } from '~/server/api/routers/weather';
|
||||||
import { api } from '~/utils/api';
|
import { api } from '~/utils/api';
|
||||||
|
|
||||||
import { IntegrationOptionsValueType } from '../WidgetsEditModal';
|
import { IntegrationOptionsValueType } from '../WidgetsEditModal';
|
||||||
|
import Link from 'next/link';
|
||||||
|
|
||||||
type LocationSelectionProps = {
|
type LocationSelectionProps = {
|
||||||
widgetId: string;
|
widgetId: string;
|
||||||
@@ -140,15 +143,41 @@ type CitySelectModalProps = {
|
|||||||
|
|
||||||
const CitySelectModal = ({ opened, closeModal, query, onCitySelected }: CitySelectModalProps) => {
|
const CitySelectModal = ({ opened, closeModal, query, onCitySelected }: CitySelectModalProps) => {
|
||||||
const { t } = useTranslation('widgets/location');
|
const { t } = useTranslation('widgets/location');
|
||||||
const { isLoading, data } = api.weather.findCity.useQuery(
|
const { isLoading, data, isError } = api.weather.findCity.useQuery(
|
||||||
{ query },
|
{ query },
|
||||||
{
|
{
|
||||||
|
retry: false,
|
||||||
enabled: opened,
|
enabled: opened,
|
||||||
refetchOnWindowFocus: false,
|
refetchOnWindowFocus: false,
|
||||||
refetchOnMount: false,
|
refetchOnMount: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isError === true)
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
title={
|
||||||
|
<Title order={4}>
|
||||||
|
{t('modal.title')} - {query}
|
||||||
|
</Title>
|
||||||
|
}
|
||||||
|
size="xl"
|
||||||
|
opened={opened}
|
||||||
|
onClose={closeModal}
|
||||||
|
zIndex={250}
|
||||||
|
>
|
||||||
|
<Center>
|
||||||
|
<Stack align="center">
|
||||||
|
<IconAlertTriangle />
|
||||||
|
<Title order={6}>Nothing found</Title>
|
||||||
|
<Text>Nothing was found, please try again</Text>
|
||||||
|
</Stack>
|
||||||
|
</Center>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
|
||||||
|
const formatter = Intl.NumberFormat('en', { notation: 'compact' });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title={
|
title={
|
||||||
@@ -191,13 +220,15 @@ const CitySelectModal = ({ opened, closeModal, query, onCitySelected }: CitySele
|
|||||||
<Text style={{ whiteSpace: 'nowrap' }}>{city.country}</Text>
|
<Text style={{ whiteSpace: 'nowrap' }}>{city.country}</Text>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
<Anchor target='_blank' href={`https://www.google.com/maps/place/${city.latitude},${city.longitude}`}>
|
||||||
<Text style={{ whiteSpace: 'nowrap' }}>
|
<Text style={{ whiteSpace: 'nowrap' }}>
|
||||||
{city.latitude}, {city.longitude}
|
{city.latitude}, {city.longitude}
|
||||||
</Text>
|
</Text>
|
||||||
|
</Anchor>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{city.population ? (
|
{city.population ? (
|
||||||
<Text style={{ whiteSpace: 'nowrap' }}>{city.population}</Text>
|
<Text style={{ whiteSpace: 'nowrap' }}>{formatter.format(city.population)}</Text>
|
||||||
) : (
|
) : (
|
||||||
<Text color="dimmed"> {t('modal.table.population.fallback')}</Text>
|
<Text color="dimmed"> {t('modal.table.population.fallback')}</Text>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user