Skip to content

Commit

Permalink
feat: 디스커버리(메인) 페이지 개발 (#7)
Browse files Browse the repository at this point in the history
* feat: Update slop-video component to use lazy loading for ReactHlsPlayer

* feat: Add Header component to widgets folder

* feat: Add constants for weekly weather data

* feat: Add layout component for web application

* feat: Add WeatherList component in Discovery page

* feat: Add WeatherCardItem component for displaying weather information

* refactor: Update stroke attributes in SVG icons

* feat: Add rain and snow weather options to model and UI components

* feat: Remove unused NavBar and StatusBar components

* refactor: Remove unused video and image files

* refactor: Update weather page imports to use new file structure

* refactor: Update weather page name and add data

* feat: Add antialiased in web page

* refactor: Delete unused icons

* feat: Create apiClient base

* feat: Add discovery API queries

* refactor: Update discovery page to use api

* refactor: Update weather folder name to discovery

* fix: Fix Build error

* refactor: Add ensureEnvVar in env
  • Loading branch information
Najeong-Kim authored Aug 16, 2024
1 parent f6df999 commit b018b28
Show file tree
Hide file tree
Showing 54 changed files with 876 additions and 204 deletions.
Binary file added public/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/congestion/mock1.png
Binary file not shown.
Binary file removed public/congestion/mock2.png
Binary file not shown.
Binary file removed public/congestion/mock3.png
Binary file not shown.
Binary file removed public/map/konjiam.jpg
Binary file not shown.
Binary file removed public/map/phoenix.png
Binary file not shown.
Binary file removed public/map/vivaldi.png
Binary file not shown.
Binary file removed public/map/yongpyong.png
Binary file not shown.
Binary file removed public/video/konjiam/beginner-base.mov
Binary file not shown.
Binary file removed public/video/konjiam/intermediate-base.mov
Binary file not shown.
Binary file removed public/video/konjiam/top-slope.mov
Binary file not shown.
Binary file removed public/video/konjiam/top.mov
Binary file not shown.
Binary file removed public/video/phoenix/luge.mov
Binary file not shown.
Binary file removed public/video/phoenix/montblanc.mov
Binary file not shown.
Binary file removed public/video/phoenix/taegi.mov
Binary file not shown.
Binary file removed public/video/yongpyong/entrance.mov
Binary file not shown.
Binary file removed public/video/yongpyong/forest.mov
Binary file not shown.
Binary file removed public/video/yongpyong/red-slope.mov
Binary file not shown.
Binary file removed public/video/yongpyong/sky-walk.mov
Binary file not shown.
Binary file removed public/video/yongpyong/starlight.mov
Binary file not shown.
Binary file removed public/video/yongpyong/yellow-slope.mov
Binary file not shown.
9 changes: 9 additions & 0 deletions src/app/(web)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { cn } from '@/shared/lib';

export default function Layout({ children }: { children: React.ReactNode }) {
return (
<div className={cn('flex size-full justify-center bg-main-5 antialiased')}>
<div className={cn('size-full max-w-[670px]')}>{children}</div>
</div>
);
}
1 change: 1 addition & 0 deletions src/app/(web)/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@/pages/discovery/ui/discovery-page';
1 change: 0 additions & 1 deletion src/app/mobile/weather/page.tsx

This file was deleted.

13 changes: 13 additions & 0 deletions src/entities/discovery/api/discovery.queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { queryOptions } from '@tanstack/react-query';
import { getDiscoveries } from './get-discoveries';

export const discoveryQueries = {
all: () => ['discovery'],

listQueryKey: () => [...discoveryQueries.all(), 'list'],
list: () =>
queryOptions({
queryKey: [...discoveryQueries.listQueryKey()],
queryFn: () => getDiscoveries(),
}),
};
9 changes: 9 additions & 0 deletions src/entities/discovery/api/get-discoveries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { DiscoveryData } from '../model';
import type { Discovery } from '../model';

export const getDiscoveries = async (): Promise<Discovery[]> => {
// const result = await apiClient.get<Discovery[]>('/discoveries');
const result = DiscoveryData;

return result;
};
1 change: 1 addition & 0 deletions src/entities/discovery/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { discoveryQueries } from './discovery.queries';
2 changes: 2 additions & 0 deletions src/entities/discovery/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * as discoveryApi from './api';
export * from './model';
121 changes: 121 additions & 0 deletions src/entities/discovery/model/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import type { Discovery, WeeklyWeather } from './model';

export const WeeklyWeatherData: WeeklyWeather[] = [
{
day: '월',
weather: 'sun',
temperature: {
lowest: '-2°',
average: '-5°',
},
},
{
day: '화',
weather: 'snow',
temperature: {
lowest: '-3°',
average: '-6°',
},
},
{
day: '수',
weather: 'sun',
temperature: {
lowest: '-1°',
average: '-4°',
},
},
{
day: '목',
weather: 'cloud',
temperature: {
lowest: '-2°',
average: '-5°',
},
},
{
day: '금',
weather: 'cloud',
temperature: {
lowest: '-1°',
average: '-4°',
},
},
{
day: '토',
weather: 'rain',
temperature: {
lowest: '-3°',
average: '-6°',
},
},
{
day: '일',
weather: 'sun',
temperature: {
lowest: '-2°',
average: '-5°',
},
},
{
day: '월',
weather: 'sun',
temperature: {
lowest: '-2°',
average: '-5°',
},
},
];

export const DiscoveryData: Discovery[] = [
{
name: '용평스키장 모나',
slope: null,
weather: {
weather: 'sun',
temperature: -5,
description: '맑음',
},
weeklyWeather: WeeklyWeatherData,
},
{
name: '휘닉스파크',
slope: 8,
weather: {
weather: 'cloud',
temperature: -3,
description: '흐리고 비',
},
weeklyWeather: WeeklyWeatherData,
},
{
name: '하이원스키장',
slope: 10,
weather: {
weather: 'rain',
temperature: -4,
description: '비',
},
weeklyWeather: WeeklyWeatherData,
},
{
name: '비발디파크',
slope: 14,
weather: {
weather: 'snow',
temperature: -6,
description: '눈',
},
weeklyWeather: WeeklyWeatherData,
},
{
name: '곤지암스키장',
slope: 8,
weather: {
weather: 'cloud',
temperature: -3,
description: '흐리고 비',
},
weeklyWeather: WeeklyWeatherData,
},
];
2 changes: 2 additions & 0 deletions src/entities/discovery/model/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { DiscoveryData } from './constants';
export type { Weather, WeeklyWeather, Discovery } from './model';
21 changes: 21 additions & 0 deletions src/entities/discovery/model/model.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export type Weather = 'sun' | 'cloud' | 'rain' | 'snow';

export type WeeklyWeather = {
day: string;
weather: Weather;
temperature: {
lowest: string;
average: string;
};
};

export type Discovery = {
name: string;
slope: number | null;
weather: {
weather: Weather;
temperature: number;
description: string;
};
weeklyWeather: WeeklyWeather[];
};
32 changes: 32 additions & 0 deletions src/pages/discovery/ui/discovery-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use client';

import { useQuery } from '@tanstack/react-query';
import DiscoveryList from '@/widgets/discovery/ui/discovery-list';
import Header from '@/widgets/header/ui/header';
import { discoveryApi } from '@/entities/discovery';
import { cn } from '@/shared/lib';

const DiscoveryPage = () => {
if (typeof window === 'undefined') {
return null;
}

return <DiscoveryPageContent />;
};

const DiscoveryPageContent = () => {
const { data: discoveryData } = useQuery(discoveryApi.discoveryQueries.list());

if (!discoveryData) return null;

return (
<div className={cn('relative size-full bg-opacity-65 bg-[url("/background.png")]')}>
<div className={cn('size-full bg-gradient-to-b from-[#8DA3DD/20] to-transparent')}>
<Header />
<DiscoveryList discoveryData={discoveryData} />
</div>
</div>
);
};

export default DiscoveryPage;
14 changes: 0 additions & 14 deletions src/pages/weather/ui/weather-page.tsx

This file was deleted.

61 changes: 61 additions & 0 deletions src/shared/api/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { API_URL } from '@/shared/config';

export class ApiClient {
private baseUrl: string;

constructor(url: string) {
this.baseUrl = url;
}

async handleResponse<TResult>(response: Response): Promise<TResult> {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}

try {
return await response.json();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) {
throw new Error('Error parsing JSON response');
}
}

public async get<TResult = unknown>(
endpoint: string,
queryParams?: Record<string, string | number>
): Promise<TResult> {
const url = new URL(endpoint, this.baseUrl);

if (queryParams) {
Object.entries(queryParams).forEach(([key, value]) => {
url.searchParams.append(key, value.toString());
});
}

const response = await fetch(url.toString(), {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

return this.handleResponse<TResult>(response);
}

public async post<TResult = unknown, TData = Record<string, unknown>>(
endpoint: string,
body: TData
): Promise<TResult> {
const response = await fetch(`${this.baseUrl}${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});

return this.handleResponse<TResult>(response);
}
}

export const apiClient = new ApiClient(API_URL);
8 changes: 8 additions & 0 deletions src/shared/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const ensureEnvVar = (value: string | undefined): string => {
if (value === undefined) {
throw new Error(`Environment variable is not set`);
}
return value;
};

export const API_URL = ensureEnvVar(process.env.NEXT_PUBLIC_API_URL);
18 changes: 0 additions & 18 deletions src/shared/icons/battery.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/shared/icons/close.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const CloseIcon = ({ className, ...args }: CloseIconProps) => {
<path
d="M12.75 5.25L5.25 12.75M12.75 12.75L5.25 5.25"
stroke="currentColor"
stroke-width="2"
strokeWidth="2"
stroke-linecap="round"
/>
</svg>
Expand Down
Loading

0 comments on commit b018b28

Please sign in to comment.