diff --git a/docker-compose.yml b/docker-compose.yml index 7328239ef..4ac34586e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,24 +32,30 @@ services: depends_on: mysql: condition: service_healthy - command: [ "yarn", "run", "migration:run-dev"] + command: ['yarn', 'run', 'migration:run-dev'] mysql: image: mysql:8 environment: - MYSQL_ROOT_PASSWORD=my-secret-pw healthcheck: - test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] + test: ['CMD', 'mysqladmin', 'ping', '-h', 'localhost'] timeout: 20s retries: 10 ports: - - '3306:3306' - - '33060:33060' + - '3307:3306' + - '3308:33060' volumes: - ./.mysql-data:/var/lib/mysql minio: image: minio/minio ports: - '9000:9000' + - '9090:9090' + environment: + - MINIO_ROOT_USER=minioadmin + - MINIO_ROOT_PASSWORD=minioadmin + - MINIO_ACCESS_KEY=minio + - MINIO_SECRET_KEY=minio123 volumes: - ./.minio-data:/data - command: server /data + command: server --console-address ":9090" /data diff --git a/server/utils/database.ts b/server/utils/database.ts index 79ec080aa..2ca60eb65 100644 --- a/server/utils/database.ts +++ b/server/utils/database.ts @@ -23,6 +23,7 @@ async function createMySQLDB(): Promise { const connection = mysql.createConnection({ charset: 'utf8mb4_unicode_ci', host: process.env.DB_HOST, + port: Number(process.env.DB_PORT) || 3306, password: process.env.DB_PASS, user: process.env.DB_USER, }); diff --git a/src/api/weather/weather.get.ts b/src/api/weather/weather.get.ts new file mode 100644 index 000000000..1ed26b5ff --- /dev/null +++ b/src/api/weather/weather.get.ts @@ -0,0 +1,26 @@ +import { useQuery } from 'react-query'; + +import { serializeToQueryUrl } from 'src/utils'; +import { axiosRequest } from 'src/utils/axiosRequest'; +import type { Weather } from 'types/weather.type'; + +type GET_WEATHER_PARAMS = { + latitude: number; + longitude: number; +}; +type GET_WEATHER_RESPONSE = Weather; + +export async function getWeather({ latitude, longitude }: GET_WEATHER_PARAMS) { + const response = await axiosRequest({ + method: 'GET', + url: `/weather${serializeToQueryUrl({ + latitude, + longitude, + })}`, + }); + return response.error ? undefined : response.data; +} + +export function useWeather({ latitude, longitude }: GET_WEATHER_PARAMS) { + return useQuery(['weather', { latitude, longitude }], () => getWeather({ latitude, longitude })); +} diff --git a/src/components/accueil/RightNavigation.tsx b/src/components/accueil/RightNavigation.tsx index f8beadc44..e4b945f77 100644 --- a/src/components/accueil/RightNavigation.tsx +++ b/src/components/accueil/RightNavigation.tsx @@ -8,12 +8,12 @@ import { AvatarImg } from '../Avatar'; import { Flag } from '../Flag'; import { CommentIcon } from '../activities/ActivityCard/CommentIcon'; import { isMascotte } from 'src/activity-types/anyActivity'; +import { useWeather } from 'src/api/weather/weather.get'; import { Map } from 'src/components/Map'; import { icons, DESC } from 'src/components/activities/utils'; import { UserContext } from 'src/contexts/userContext'; import { useActivities } from 'src/services/useActivities'; import { useActivity } from 'src/services/useActivity'; -import { useWeather } from 'src/services/useWeather'; import { primaryColor } from 'src/styles/variables.const'; import { getUserDisplayName, toDate } from 'src/utils'; import { ActivityType } from 'types/activity.type'; @@ -24,7 +24,7 @@ export const RightNavigation = ({ activityUser, displayAsUser = false }: { activ const router = useRouter(); const [localTime, setLocalTime] = React.useState(null); const { user } = React.useContext(UserContext); - const weather = useWeather({ activityUser }); + const { data: weather } = useWeather({ latitude: activityUser.position.lat, longitude: activityUser.position.lng }); const { activity: userMascotte } = useActivity(activityUser.mascotteId || -1); const { activities } = useActivities({ limit: 200, @@ -41,7 +41,7 @@ export const RightNavigation = ({ activityUser, displayAsUser = false }: { activ // ---- Get user weather and time ---- React.useEffect(() => { - if (weather !== null) { + if (weather) { const timezone = weather.timezone; const updateLocalTime = () => { const time = new Date(); @@ -217,8 +217,12 @@ export const RightNavigation = ({ activityUser, displayAsUser = false }: { activ {activityUser.city} {localTime} - - {weather.temperature}°C + {weather && ( + <> + + {weather.temperature}°C + + )} )} {/* MAP / METEO */} diff --git a/src/services/useWeather.ts b/src/services/useWeather.ts deleted file mode 100644 index 31f2e7bcc..000000000 --- a/src/services/useWeather.ts +++ /dev/null @@ -1,34 +0,0 @@ -import React from 'react'; -import type { QueryFunction } from 'react-query'; -import { useQuery } from 'react-query'; - -import { serializeToQueryUrl } from 'src/utils'; -import { axiosRequest } from 'src/utils/axiosRequest'; -import type { User } from 'types/user.type'; -import type { Weather } from 'types/weather.type'; - -export const useWeather = ({ activityUser }: { activityUser: User }): Weather | null => { - const getWeather: QueryFunction = React.useCallback(async () => { - if (!activityUser) { - return null; - } - - const response = await axiosRequest({ - method: 'GET', - url: `/weather${serializeToQueryUrl({ - latitude: activityUser.position.lat, - longitude: activityUser.position.lng, - })}`, - }); - return response.error ? null : (response.data as Weather); - }, [activityUser]); - const { data, isLoading, error } = useQuery( - ['weather', { userId: activityUser ? activityUser.id : undefined }], - getWeather, - ); - - if (isLoading || error) { - return null; - } - return data || null; -};