Skip to content

Commit d02b92c

Browse files
authored
Merge pull request #12 from ananjaemin/main
dev branch update
2 parents b6afeb0 + ab9221a commit d02b92c

File tree

12 files changed

+126
-46
lines changed

12 files changed

+126
-46
lines changed

src/components/common/FileListBox/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ type FileListBoxProps = {
66
filename: string;
77
size: string;
88
LastModified: any;
9+
click: () => void;
910
};
1011

11-
export const FileListBox: React.FC<FileListBoxProps> = ({ filename, size, LastModified }) => (
12-
<S.FileListBoxContainer>
13-
파일이름: {filename} / 크기:{size} / 업로드날짜:{LastModified.getFullYear()}-
14-
{LastModified.getMonth() + 1}-{LastModified.getDate()}
12+
export const FileListBox: React.FC<FileListBoxProps> = ({
13+
filename,
14+
size,
15+
LastModified,
16+
click,
17+
}) => (
18+
<S.FileListBoxContainer onClick={click}>
19+
파일이름: {filename} / 크기:{size} / 업로드날짜:{LastModified.year}-{LastModified.month}-
20+
{LastModified.day}
1521
</S.FileListBoxContainer>
1622
);

src/pages/download/index.tsx

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,48 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
2+
import { useSelector } from 'react-redux';
3+
import { useNavigate } from 'react-router-dom';
4+
import { toast } from 'react-toastify';
25

36
import { Button } from '../../components';
7+
import { RootState } from '../../state/reducers';
8+
import { getFileSize, getDate } from '../../utils';
49
import * as S from './styled';
510

6-
export const DownloadPage: React.FC = () => (
7-
<S.DownloadPageContainer>
8-
<S.DownloadPageButtonSection>
9-
<Button click={() => {}} bgColor="var(--color-button-secondary)" label="다운로드" />
10-
<Button click={() => {}} bgColor="var(--color-button-secondary)" label="신고" />
11-
</S.DownloadPageButtonSection>
12-
</S.DownloadPageContainer>
13-
);
11+
export const DownloadPage: React.FC = () => {
12+
const navigate = useNavigate();
13+
const downloadFileProps: any = useSelector((state: RootState) => state.DownloadFileProps);
14+
const { year, month, day } = getDate(downloadFileProps.LastModified);
15+
useEffect(() => {
16+
if (
17+
downloadFileProps.Name === null ||
18+
downloadFileProps.Size === null ||
19+
downloadFileProps.LastModified === null
20+
) {
21+
navigate(-1);
22+
}
23+
});
24+
return (
25+
<S.DownloadPageContainer>
26+
<S.DonwloadFileBox>
27+
파일이름:{downloadFileProps.Name} / 크기:{getFileSize(downloadFileProps.Size)} / 업로드된
28+
날짜:
29+
{year}-{month}-{day}
30+
</S.DonwloadFileBox>
31+
<S.DownloadPageButtonSection>
32+
<a href={`https://tfb.minpeter.cf/dl/${downloadFileProps.Name}`}>
33+
<Button click={() => {}} bgColor="var(--color-button-primary)" label="다운로드" />
34+
</a>
35+
<Button
36+
click={() => {
37+
toast.success('제작중!', {
38+
autoClose: 1000,
39+
position: toast.POSITION.BOTTOM_RIGHT,
40+
});
41+
}}
42+
bgColor="var(--color-button-secondary)"
43+
label="신고"
44+
/>
45+
</S.DownloadPageButtonSection>
46+
</S.DownloadPageContainer>
47+
);
48+
};

src/pages/download/styled.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
import styled from '@emotion/styled';
22

33
export const DownloadPageContainer = styled.div`
4+
display: flex;
5+
flex-direction: column;
46
width: 100%;
57
`;
68

79
export const DownloadPageButtonSection = styled.div`
10+
display: flex;
811
width: 100%;
9-
min-width: 300px;
12+
justify-content: center;
13+
margin-top: 3rem;
14+
`;
15+
16+
export const DonwloadFileBox = styled.div`
17+
background-color: var(--color-backgorund-filelistbox);
18+
color: var(--color-text-filelistbox);
19+
border-radius: 10px;
20+
padding: 1.2rem 1.2rem 1.2rem 1.2rem;
1021
display: flex;
11-
justify-content: space-between;
22+
flex-direction: row;
23+
align-items: center;
24+
font-size: 2.2rem;
1225
`;

src/pages/filelist/index.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
import axios from 'axios';
22
import React, { useEffect, useState } from 'react';
3+
import { useDispatch } from 'react-redux';
4+
import { useNavigate } from 'react-router-dom';
5+
import { bindActionCreators } from 'redux';
36

47
import { FileListBox } from '../../components';
5-
import { getFileSize, getShortFileName } from '../../utils';
8+
import { actionCreators } from '../../state';
9+
import { getFileSize, getShortFileName, getDate } from '../../utils';
610
import * as S from './styled';
711

812
export const FileListPage: React.FC = () => {
13+
const navigate = useNavigate();
914
const [loading, setLoading] = useState(false);
1015
const SkeletonUIRandomWidth = ['50', '55', '60', '65', '70', '75', '80'];
16+
const dispatch = useDispatch();
17+
const { SetDownloadFileProps } = bindActionCreators(actionCreators, dispatch);
1118
const [fileList, setFileList] = useState<any[]>();
1219
const getFileList = async () => {
1320
await axios({
1421
method: 'get',
1522
url: 'https://tfb.minpeter.cf/list',
1623
})
1724
.then((res) => {
18-
setFileList(res.data.list);
25+
setFileList(res.data.list); //파일리스트 요소 갯수에 따른 핸들링 추가예정
1926
setTimeout(() => {
2027
setLoading(true); //loading 확인하고싶으면 false로 바꿔주세요.
21-
}, 2000);
28+
}, 1500);
2229
})
2330
.catch((err) => {
2431
console.log(err);
@@ -37,7 +44,16 @@ export const FileListPage: React.FC = () => {
3744
key={index}
3845
filename={getShortFileName(item.Name)}
3946
size={getFileSize(item.Size)}
40-
LastModified={new Date(item.LastModified)}
47+
LastModified={getDate(item.LastModified)}
48+
click={() => {
49+
SetDownloadFileProps({
50+
Name: item.Name,
51+
Size: item.Size,
52+
LastModified: item.LastModified,
53+
//passowrd 유무 추가예정
54+
});
55+
navigate('/download');
56+
}}
4157
/>
4258
))}
4359
</S.FileListPageContainer>

src/state/action-types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum ActionType {
22
SusccesFileProps = 'SusccesFileProps',
33
DeleteFileName = 'DeleteFileName',
4+
DownloadFileProps = 'DownloadFileProps',
45
}

src/state/actions-creators/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ export const SetDeleteFileName = (name: string) => (dispatch: Dispatch<Action>)
1616
name: name,
1717
});
1818
};
19+
20+
export const SetDownloadFileProps = (props: any) => (dispatch: Dispatch<Action>) => {
21+
dispatch({
22+
type: ActionType.DownloadFileProps,
23+
props: props,
24+
});
25+
};

src/state/actions/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ interface DeleteFileProps {
1010
name: string;
1111
}
1212

13-
export type Action = SusccesFileProps | DeleteFileProps;
13+
interface DownloadFileProps {
14+
type: ActionType.DownloadFileProps;
15+
props: any;
16+
}
17+
18+
export type Action = SusccesFileProps | DeleteFileProps | DownloadFileProps;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ActionType } from '../action-types';
2+
import { Action } from '../actions';
3+
4+
const reducer = (
5+
state: any = { Name: null, Size: null, LastModified: null },
6+
action: Action,
7+
): any => {
8+
switch (action.type) {
9+
case ActionType.DownloadFileProps:
10+
return action.props;
11+
default:
12+
return state;
13+
}
14+
};
15+
16+
export default reducer;

src/state/reducers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { combineReducers } from 'redux';
22

33
import DeleteFileName from './DeleteFileName';
4+
import DownloadFileProps from './DownloadFileProps';
45
import SuccessFileProps from './SuccessFileProps';
56

67
const reducers = combineReducers({
78
SuccessFileProps: SuccessFileProps,
89
DeleteFileName: DeleteFileName,
10+
DownloadFileProps: DownloadFileProps,
911
});
1012

1113
export default reducers;

src/utils/getDate.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const getDate = (date: string) => {
2+
const NewDate = new Date(date);
3+
return { year: NewDate.getFullYear(), month: NewDate.getMonth() + 1, day: NewDate.getDay() };
4+
};

0 commit comments

Comments
 (0)