Skip to content

Commit

Permalink
Merge pull request #373 from waterkail/main
Browse files Browse the repository at this point in the history
[이현승]  week12
  • Loading branch information
13akstjq authored May 6, 2024
2 parents 5882acc + 3a682e9 commit 8159ddc
Show file tree
Hide file tree
Showing 51 changed files with 1,250 additions and 1,049 deletions.
38 changes: 7 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ In the project directory, you can run:
### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.
The page will reload if you make edits.\
You will also see any lint errors in the console.

### `npm test`

Expand All @@ -31,40 +31,16 @@ See the section about [deployment](https://facebook.github.io/create-react-app/d

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**
**Note: this is a one-way operation. Once you `eject`, you cant go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
If you arent satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point youre on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
1,153 changes: 465 additions & 688 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 15 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
{
"name": "1-weekly-mission",
"name": "tsbeam",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.3",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.96",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"@types/react-router-dom": "^5.3.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-intersection-observer": "^9.10.1",
"react-router-dom": "^6.23.0",
"react-scripts": "5.0.1",
"react-share": "^5.1.0",
"react-toastify": "^10.0.5",
"styled-components": "^6.1.8",
"styled-components": "^6.1.9",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand All @@ -38,5 +44,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/styled-components": "^5.1.34"
}
}
11 changes: 6 additions & 5 deletions src/Hooks/useData.js → src/Hooks/useData.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { useCallback, useState } from "react";

export function useData(asyncFunction) {
const [data, setData] = useState(null);
export function useData(
asyncFunction: (pram?: string | number) => Promise<any>
) {
const [data, setData] = useState<any>(null);

const getData = useCallback(
async (value = null) => {
async (value?: string | number) => {
try {
const result = await asyncFunction(value);
setData(result);
} catch (err) {
console.log(err);
setData(null);
}
},
[asyncFunction]
);

return [data, getData];
return [data, getData] as [any, (value?: string | number) => Promise<void>];
}
12 changes: 6 additions & 6 deletions src/Main.js → src/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';
import { BrowserRouter, Routes, Route, Link } from "react-router-dom";

import SharedPage from './pages/SharedPage';
import FolderPage from './pages/FolderPage';
import GlobalStyle from './components/GlobalStyle';
import SharedPage from "./pages/SharedPage";
import FolderPage from "./pages/FolderPage";
import GlobalStyle from "./components/GlobalStyle";

function Main() {
const Main = () => {
return (
<BrowserRouter>
<GlobalStyle />
Expand All @@ -31,6 +31,6 @@ function Main() {
</Routes>
</BrowserRouter>
);
}
};

export default Main;
13 changes: 0 additions & 13 deletions src/Portal/Portal.js

This file was deleted.

21 changes: 21 additions & 0 deletions src/Portal/Portal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ReactNode, useMemo } from "react";
import { createPortal } from "react-dom";

interface Props {
children: ReactNode;
elementId: string;
}

function Portal({ children, elementId }: Props) {
const rootElement = useMemo(
() => document.getElementById(elementId),
[elementId]
);
if (rootElement instanceof HTMLElement)
return createPortal(children, rootElement);
else {
return <></>;
}
}

export default Portal;
Binary file added src/asset/inputclose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 69 additions & 23 deletions src/components/AddLink.js → src/components/AddLink.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,50 @@
import styled from "styled-components";
import linkIcon from "../asset/linkIcon.svg";
import { PRIMARY, WHITE } from "./color";
import { useRef, useState } from "react";
import { FormEvent, useRef, useState } from "react";
import Portal from "../Portal/Portal";
import ModalAddLink from "./Modal/ModalAddLink";
import { useInView } from "react-intersection-observer";

const BAR_COLOR = WHITE;
const BAR_BORDER_RADIUS = "15px";
const LinkPlaceHolder = "링크를 추가해 보세요";

const Div = styled.div`
display: flex;
padding: 24px 0;
margin-top: 40px;
width: 100%;
justify-content: center;
align-items: center;
&.foot {
position: fixed;
bottom: 0px;
left: 0px;
right: 0px;
z-index: 3;
padding: 24px 32px;
margin: 0;
background-color: #f0f6ff;
}
&.unseen {
display: none;
}
@media (max-width: 767px) {
margin-top: 14px;
}
`;

const AddlinkBar = styled.form`
display: flex;
padding: 16px 20px;
width: 100%;
max-width: 800px;
min-width: 336px;
margin: 40px 0 30px;
border-radius: ${BAR_BORDER_RADIUS};
background-color: ${BAR_COLOR};
border: 1px solid ${PRIMARY};
Expand All @@ -39,7 +68,6 @@ const AddlinkBar = styled.form`
}
@media (max-width: 767px) {
margin-top: 14px;
padding: 8px 10px;
}
`;
Expand Down Expand Up @@ -81,33 +109,51 @@ const AddLinkButton = styled.button`
white-space: nowrap;
`;

const AddLink = ({ folder }) => {
const AddLink = useRef(null);
const Observed = styled.div`
height: 1px;
margin-bottom: 53px;
&.big {
height: 137px;
@media (max-width: 767px) {
height: 105px;
}
}
`;

const AddLink = ({ folder, footView }: { folder: any; footView: boolean }) => {
const AddLink = useRef<HTMLInputElement>(null);
const [add, setAdd] = useState(false);
const [url, setUrl] = useState("");
const [url, setUrl] = useState<string>();
const [target, inView] = useInView();

const handleSubmit = (e) => {
const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
setAdd(!add);
setUrl(AddLink.current.value);
setUrl(AddLink.current?.value);
};

return (
<AddlinkBar onSubmit={handleSubmit}>
<LinkLabel htmlFor="AddLink">링크 추가</LinkLabel>
<LinkInput
type="text"
id="AddLink"
ref={AddLink}
placeholder={LinkPlaceHolder}
/>
<AddLinkButton type="submit">추가하기</AddLinkButton>
<Portal elementId="modal-root">
{add && (
<ModalAddLink onClick={handleSubmit} url={url} folder={folder} />
)}
</Portal>
</AddlinkBar>
<>
<Div className={`${inView ? "" : "foot"} ${footView ? "unseen" : ""}`}>
<AddlinkBar onSubmit={handleSubmit}>
<LinkLabel htmlFor="AddLink">링크 추가</LinkLabel>
<LinkInput
type="text"
id="AddLink"
ref={AddLink}
placeholder={LinkPlaceHolder}
/>
<AddLinkButton type="submit">추가하기</AddLinkButton>
<Portal elementId="modal-root">
{add && (
<ModalAddLink onClick={handleSubmit} url={url} folder={folder} />
)}
</Portal>
</AddlinkBar>
</Div>
<Observed ref={target} className={inView ? "" : "big"}></Observed>
</>
);
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/Api/Api.js → src/components/Api/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function getFolderData() {
return response.json();
}

export async function getUsersData(userId) {
export async function getUsersData(userId?: string | number) {
const response = await fetch(`${BASE_URL}/users/${userId}`, {
method: "GET",
headers: { accept: `*/*` },
Expand All @@ -40,7 +40,7 @@ export async function getFoldersData() {
return response.json();
}

export async function getLinksData(folderId) {
export async function getLinksData(folderId?: string | number) {
const response = await fetch(
`${BASE_URL}/users/1/links?folderId=${folderId}`,
{
Expand Down
14 changes: 11 additions & 3 deletions src/components/App.js → src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import Header from "./Header";
import Footer from "./Footer";
import { useCallback, useEffect, useState } from "react";
import { ReactNode, useCallback, useEffect, useState } from "react";
import { getUsersData } from "./Api/Api";
import { useData } from "../Hooks/useData";

function App({ children, headerFixed }) {
function App({
children,
headerFixed,
foot,
}: {
children: ReactNode;
headerFixed: boolean;
foot?: (node?: Element | null | undefined) => void;
}) {
const [user, getUser] = useData(getUsersData);
const [isLogIn, setIsLogIn] = useState(true);

Expand All @@ -30,7 +38,7 @@ function App({ children, headerFixed }) {
fixed={headerFixed}
/>
{children}
<Footer />
<Footer observer={foot} />
</>
);
}
Expand Down
Loading

0 comments on commit 8159ddc

Please sign in to comment.