Skip to content

Commit

Permalink
Merge pull request #15 from TEAM-Hearus/develop
Browse files Browse the repository at this point in the history
Chore: mockAPI ์—ฐ๊ฒฐ ๋ฐ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ • ๋ฐฐํฌ ํ…Œ์ŠคํŠธ
  • Loading branch information
Nangniya authored Jul 9, 2024
2 parents 41cf536 + a5da610 commit e16b265
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
push:
branches:
- main
env:
VITE_MOCK_API: ${{ secrets.VITE_MOCK_API }}
jobs:
build_and_deploy:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ permissions:
checks: write
contents: read
pull-requests: write
env:
VITE_MOCK_API: ${{ secrets.VITE_MOCK_API }}
jobs:
build_and_preview:
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ dist
dist-ssr
*.local

.env


# Editor directories and files
.vscode/*
!.vscode/extensions.json
Expand Down
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^5.50.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.24.0",
"styled-reset": "^4.5.2"
},
"devDependencies": {
"@tanstack/react-query-devtools": "^5.50.1",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.13.1",
Expand Down
9 changes: 7 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Reset } from 'styled-reset';
import Router from './pages';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

const queryClient = new QueryClient();

function App() {
return (
<>
<QueryClientProvider client={queryClient}>
<Reset />
<Router />
</>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const mockAPI_URL: string = import.meta.env.VITE_MOCK_API;

export default mockAPI_URL;
26 changes: 26 additions & 0 deletions src/apis/schedule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import mockAPI_URL from '.';
import { IScheduleElement } from '../constants/schedule';

interface IGetScheduleResponse {
status: string;
msg: string;
object: {
id: number;
scheduleElements: IScheduleElement[];
name: string;
userId: string | null;
};
success: boolean;
}

export const getSchedule = async (
name: string,
): Promise<IScheduleElement[]> => {
try {
const res = await fetch(`${mockAPI_URL}/schedule/getSchedule?name=${name}`);
const data: IGetScheduleResponse = await res.json();
return data.object['scheduleElements'];
} catch (error) {
throw error;
}
};
12 changes: 10 additions & 2 deletions src/pages/Main/TimeTable/WeeklyTimeTable/WeeklyTimeTable.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { useQuery } from '@tanstack/react-query';
import TimeTableItem from '../../../../components/common/TimeTableItem/TimeTableItem';
import { TIMELIST, scheduleElements } from '../../../../constants/schedule';
import { IScheduleElement, TIMELIST } from '../../../../constants/schedule';
import styles from './WeeklyTimeTable.module.scss';
import { getSchedule } from '../../../../apis/schedule';

const name = '๊ฑด๊ตญ๋Œ€ํ•™๊ต 3-1ํ•™๊ธฐ'; // ์ž„์‹œ ์ง€์ •

const WeeklyTimeTable = () => {
const daysOfWeek = ['์ผ', '์›”', 'ํ™”', '์ˆ˜', '๋ชฉ', '๊ธˆ', 'ํ† '];
const { data } = useQuery<IScheduleElement[], Error>({
queryKey: ['schedule', name],
queryFn: () => getSchedule(name),
});
return (
<div className={styles.table}>
<div className={styles.dayOfWeekRow}>
Expand All @@ -19,7 +27,7 @@ const WeeklyTimeTable = () => {
<span className={styles.time}>{time}</span>
</div>
))}
{scheduleElements.map((schedule) => (
{data?.map((schedule) => (
<TimeTableItem key={schedule.id} {...schedule} />
))}
</div>
Expand Down

0 comments on commit e16b265

Please sign in to comment.