๐ŸŽฏ @react-beautiful-dnd ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ†ตํ•ด drag and drop ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ณ , Firebase๋กœ Login ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ณ  ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.


๐Ÿ“— Today I Learned

Drag and Drop ๊ธฐ๋Šฅ ๊ตฌํ˜„

@react-beautiful-dnd ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ด์„œ Drag and Drop ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.

  • <DragDropContext/> : ๋“œ๋ž˜๊ทธ ์•ค ๋“œ๋กญ ๊ธฐ๋Šฅ์„ ํ™œ์„ฑํ™”ํ•˜๊ณ ์ž ํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์˜์—ญ์„ ๊ฐ์‹ธ๋Š” ์ปดํฌ๋„ŒํŠธ์ž…๋‹ˆ๋‹ค.

  • <Droppable/> : ๋“œ๋กญ์ด ๊ฐ€๋Šฅํ•œ ์˜์—ญ์ž…๋‹ˆ๋‹ค.

  • <Draggable /> : ๋“œ๋ž˜๊ทธํ•  ์ˆ˜ ์žˆ๋Š” ์š”์†Œ์ž…๋‹ˆ๋‹ค.

App.tsx

List.tsx

Task.tsx




Firebase ์—ฐ๊ฒฐ

Firebase๋Š” Google์—์„œ ์ œ๊ณตํ•˜๋Š” ๋ฐฑ์—”๋“œ ํ”Œ๋žซํผ์œผ๋กœ, ์„œ๋ฒ„ ์—†์ด๋„ ๋น ๋ฅด๊ฒŒ ์•ฑ์„ ์ œ์ž‘ํ•˜๊ณ  ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋„์™€์ฃผ๋Š” ์„œ๋น„์Šค์ž…๋‹ˆ๋‹ค.


1๏ธโƒฃ Firebase์— ๋กœ๊ทธ์ธํ•˜์—ฌ Go to console ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์ฝ˜์†”์— ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค.


2๏ธโƒฃ ํ”„๋กœ์ ํŠธ๋ฅผ ์„ ํƒํ•˜๊ณ  Firebase Hosting์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

3๏ธโƒฃ ํ”„๋กœ์ ํŠธ ์ด๋ฆ„์„ ์„ค์ •ํ•˜๊ณ , ๊ณ„์† ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.

4๏ธโƒฃ AI ์ง€์› ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•˜๊ณ , ๊ณ„์† ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.

5๏ธโƒฃ ์• ๋„๋ฆฌํ‹ฑ์Šค ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•˜๊ณ , ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ ๋ฒ„ํŠผ๋ฅผ ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค.
(ํ˜„์žฌ๋Š” ๊ฐ„๋‹จํ•œ ํ”„๋กœ์ ํŠธ ๋ฐฐํฌ๊ธฐ ๋•Œ๋ฌธ์— ์• ๋„๋ฆฌํ‹ฑ์Šค๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.)

6๏ธโƒฃ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ค๊ณ  ๊ฐ€์šด๋ฐ์— </>(์›น) ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์‹œ์ž‘ํ•ด์ค๋‹ˆ๋‹ค.

7๏ธโƒฃ ์•ฑ ๋‹‰๋„ค์ž„์„ ์ ์–ด์ฃผ๊ณ  ๋“ฑ๋กํ•ด์ค๋‹ˆ๋‹ค.

8๏ธโƒฃ npm์œผ๋กœ Firebase๋ฅผ ์„ค์น˜ํ•ด์ฃผ๊ณ , firebase.ts ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์„œ ์•„๋ž˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋„ฃ๊ณ  ์ฝ˜์†”๋กœ ์ด๋™ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.




Google Login / LogOut ๊ธฐ๋Šฅ ๊ตฌํ˜„

1๏ธโƒฃ Authentication์„ ๋ˆŒ๋Ÿฌ ์ธ์ฆ ๊ด€๋ฆฌ ์„ค์ •์„ ํ•ฉ๋‹ˆ๋‹ค.

2๏ธโƒฃ ์‹œ์ž‘ํ•˜๊ธฐ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.

3๏ธโƒฃ ์ ์šฉํ•˜๊ณ  ์‹ถ์€ ๋กœ๊ทธ์ธ ์—…์ฒด๋ฅผ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.

4๏ธโƒฃ ์‚ฌ์šฉ ์„ค์ • ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ๊ณต๊ฐœ์šฉ ์ด๋ฆ„๊ณผ ์ด๋ฉ”์ผ์„ ๋„ฃ์–ด ์ €์žฅ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.

5๏ธโƒฃ ์„ค์ •์ด ๋งˆ๋ฌด๋ฆฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
(์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์ƒˆ ์ œ๊ณต์—…์ฒด ์ถ”๊ฐ€ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ๋™์ผํ•œ ๊ณผ์ •์„ ์ˆ˜ํ–‰ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.)


userSlice.ts

import { createSlice } from '@reduxjs/toolkit';

const initialState = {
  id: '',
  email: '',
};

const userSlice = createSlice({
  name: 'user',
  initialState,
  reducers: {
    setUser: (state, action) => {
      state.email = action.payload.email;
      state.id = action.payload.id;
    },
    removeUser: (state) => {
      state.email = '';
      state.id = '';
    },
  },
});

export const { setUser, removeUser } = userSlice.actions;
export const userReducer = userSlice.reducer;

BoardList.tsx

์ƒ์„ฑํ•œ reducer๋ฅผ dispatch(์•ก์…˜)์œผ๋กœ ๋ถˆ๋Ÿฌ์™€ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

const handleLogin = () => {
    signInWithPopup(auth, provider)
      .then((userCredential) => {
        console.log(userCredential);
        dispatch(
          setUser({
            email: userCredential.user.email,
            id: userCredential.user.uid,
          })
        );
      })
      .catch((error) => {
        console.log(error);
      });
  };

  const handleSignOut = () => {
    signOut(auth)
      .then(() => {
        dispatch(removeUser());
      })
      .catch((error) => console.log(error));
  };

[๊ฒฐ๊ณผ ํ™”๋ฉด] - ๊ตฌ๊ธ€ ๋กœ๊ทธ์ธ ํ›„, user์— id, email์ด ์ž˜ ๋“ค์–ด๊ฐ„ ๋ชจ์Šต




๋ฐฐํฌํ•˜๊ธฐ

๐Ÿ’ก Github์— ํŒŒ์ผ์ด ์ €์žฅ๋˜์–ด์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.


1๏ธโƒฃfirebase๋กœ ๋ฐฐํฌํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ „์—ญ์œผ๋กœ firebase-tools๋ฅผ ์„ค์น˜ํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

$ npm install -g firebase-tools

2๏ธโƒฃfirebase์— ๋กœ๊ทธ์ธ์„ ํ•ด์ค๋‹ˆ๋‹ค.

$ firebase login

3๏ธโƒฃ ์ฝ”๋“œ๋ฅผ ์„œ๋น„์Šค์— ์˜ฌ๋ฆด ์ˆ˜ ์žˆ๋Š” ํ˜•ํƒœ๋กœ ์••์ถ•ํ•˜๊ณ  ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

$ npm run build

4๏ธโƒฃ firebase ์ดˆ๊ธฐ ์„ค์ •์„ ํ•ด์ค๋‹ˆ๋‹ค.

$ firebase init

? Are you ready to proceed? Yes

โ—‹ Hosting: Configure files for Firebase Hosting and (optionally) set up Github Action deploys

Use an existing project

ํ”„๋กœ์ ํŠธ์ด๋ฆ„

? What do you want to use as your public directory? dist

? Configure as a single-page app (rewrite all urls to /index.html) Yes

? Set up automatic builds and deploys with Github? Yes

? File dist/index.html already exists. Overwrite? No


? For which Github repository would you like to set up a Github workflow? ๋‹‰๋„ค์ž„/ํ”„๋กœ์ ํŠธ์ด๋ฆ„

? Set up the workflow to run a build script before every deploy? Yes

? What script should be run before every deploy? npm ci && npm run build

? Set up automatic deployment to your site's live channel when a PR is merged? Yes

? What is the name of the Github branch associated with your site's live channel? main

5๏ธโƒฃ ์„ค์ •์„ ํ•ด์ค€ ๋’ค์— Github์— pushํ•ด ์ค๋‹ˆ๋‹ค.

git add .
git commit -m 'deploy'
git push

6๏ธโƒฃ Github ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ์—์„œ Actions ํƒญ์— ๋“ค์–ด๊ฐ€ ๋ฐฐํฌํ•œ ์ปค๋ฐ‹์œผ๋กœ ๋“ค์–ด๊ฐ€์ค๋‹ˆ๋‹ค.

7๏ธโƒฃ build_and_deploy๋กœ ๋“ค์–ด๊ฐ€์ค๋‹ˆ๋‹ค.

8๏ธโƒฃ ํ•ด๋‹น ๊ฒฝ๋กœ๋กœ ๋“ค์–ด๊ฐ€๋ฉด ๋ฐฐํฌ๋œ ์‚ฌ์ดํŠธ ์ฃผ์†Œ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.




โœ๏ธ ํšŒ๊ณ 

Firebase๋ฅผ ํ™œ์šฉํ•˜๋ฉด์„œ ๋กœ๊ทธ์ธ ๊ธฐ๋Šฅ ๊ตฌํ˜„๋ถ€ํ„ฐ ๋ฐฐํฌ๊นŒ์ง€ ๋น„๊ต์  ์ˆ˜์›”ํ•˜๊ฒŒ ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. ํŠนํžˆ Github Actions์™€ ์—ฐ๋™ํ•˜์—ฌ ์ž๋™ํ™”๋œ ๋ฐฐํฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ์ ์—์„œ ๋ฐฐํฌ ๊ณผ์ •์— ๋Œ€ํ•œ ๋ถ€๋‹ด์ด ์ค„์–ด๋“  ๋А๋‚Œ์ด๋‹ค.

profile
๐ŸŒฑ๊ฐœ๋ฐœ ๊ธฐ๋ก์žฅ

0๊ฐœ์˜ ๋Œ“๊ธ€