[TIL] 211209

Lee SyongΒ·2021λ…„ 12μ›” 9일
0

TIL

λͺ©λ‘ 보기
113/204
post-thumbnail

πŸ“ 였늘 ν•œ 것

  1. SCSS μž‘μ„± 마무리

  2. populate 쀑첩 μ‚¬μš© / form에 font-awesome μ•„μ΄μ½˜ λ„£κΈ° / shared.scss μž‘μ„± / 이미지 λΉ„μœ¨μ— 맞좰 μ›ν˜•μœΌλ‘œ 자λ₯΄κΈ° / ν”„λ‘œν•„ 이미지가 μ—†λŠ” 경우 / ν…μŠ€νŠΈ 수직 쀑앙 μ •λ ¬


πŸ“š 배운 것

1. styles

전체 μ½”λ“œλŠ” κΉƒν—ˆλΈŒμ— 올림
μ—¬κΈ°μ—λŠ” μ–΄λ €μ› λ˜ λΆ€λΆ„λ“€λ§Œ λ”°λ‘œ 정리

1) populate 쀑첩 μ‚¬μš©

User object의 videos ν•„λ“œμ˜ _id 값을 μ‹€μ œ Video objectλ“€λ‘œ λ°”κΎΈλ©΄μ„œ κ·Έ Video object의 owner ν•„λ“œμ˜ _id 값도 μ‹€μ œ User object둜 λ°”κΎΌλ‹€.

// videoController.js
export const see = async (req, res) => {
  const { id } = req.params;
  const videos = await User.find(id).populate({
    path: "videos",
    populate: {
      path: "owner",
      model: "User",
    },
  });
};

2) form에 font-awesome μ•„μ΄μ½˜ λ„£κΈ°

input(value="search now", type="submit")을 μ‚­μ œν•˜κ³  λŒ€μ‹ μ— button을 μΆ”κ°€ν–ˆλ‹€.
κ·Έ ν›„ position relative와 absoluteλ₯Ό μ΄μš©ν•΄ μœ„μΉ˜λ₯Ό μž‘μ•˜λ‹€.

//- search.pug

form(method="GET").search-form
  input(name="keyword", placeholder="Search by keywords", required, autofocus)
  button
    i.fas.fa-search
// search.scss
.search-form {
  position: relative;
  button {
    position: absolute;
    right: 5px;
    top: 7px;
    font-size: $font-regular;
    background-color: transparent;
    color: $bg;
    border-style: none;
  }
}

3) ν…μŠ€νŠΈ 수직 쀑앙 μ •λ ¬

[CSS] ν…μŠ€νŠΈ μ„Έλ‘œ 쀑앙 μ •λ ¬ 4가지 μ°Έκ³ 

li {
  margin-left: 44px;
  text-transform: uppercase;
  font-weight: bold;
  display: table;
  a {
    display: table-cell;
    vertical-align: middle;
  }
}

4) shared.scss μž‘μ„±

  • container
  • video mixin container
  • empty message
  • joinκ³Ό login νŽ˜μ΄μ§€λ₯Ό μ˜€κ°€λŠ” auth switch
  • ν”„λ‘œν•„ 이미지
.container {
  display: flex;
  flex-direction: column;
  margin: 40px auto;
  padding: 40px;
  max-width: 400px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  hr {
    width: 90%;
    border: 1px solid rgba(255, 255, 255, 0.4);
  }
}

.video-mixin__container {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
  margin: 80px 0;
}

.empty-message {
  font-size: $font-regular;
}

.auth-switch {
  margin: 20px 0;
  font-size: $font-small;
  text-align: center;
  a {
    text-decoration: underline;
    transition: all 300ms;
  }
  a:hover {
    color: $red;
  }
}

.profile-outer-box {
  width: 60px;
  .profile-inner-box {
    padding-top: 100%;
    overflow: hidden;
    position: relative;
    border-radius: 50%;
    .profile-img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
  }
}

5) 이미지 λΉ„μœ¨ 맞좰 μ›ν˜•μœΌλ‘œ 자λ₯΄κΈ°

[TIL] 210925 δΈ­ λΉ„μœ¨ μœ μ§€ν•˜λŠ” λ°˜μ‘ν˜• 이미지 λ§Œλ“€κΈ°λ₯Ό μ°Έκ³ ν•΄μ„œ μˆ˜μ •ν–ˆλ‹€.

그런데 μœ„μ—μ„œ μ •λ¦¬ν–ˆλ˜ λŒ€λ‘œ μž‘μ„±ν•˜λ‹ˆκΉŒ μ΄λ―Έμ§€μ˜ 크기가 μ–΄λ–»λ“  상관없이 μ€‘μ•™μ—μ„œ 무쑰건 (80x80)px을 μž˜λΌλ‚΄μ„œ μ΄λ―Έμ§€μ˜ μΌλΆ€λΆ„λ§Œ λ³΄μ—¬μ£ΌλŠ” λ¬Έμ œκ°€ μžˆμ—ˆλ‹€.

λ‚΄κ°€ μ›ν•˜λŠ” 건 μ΄λ―Έμ§€μ˜ μ€‘μ•™μ—μ„œ λ¨Όμ € 짧은 변을 κΈ°μ€€μœΌλ‘œ μ •μ‚¬κ°ν˜•μœΌλ‘œ 자λ₯Έ 후에 (80x80)px의 μ›ν˜•μ— λ§žμΆ°μ„œ λ³΄μ—¬μ£ΌλŠ” κ²ƒμ΄μ—ˆλ‹€.

width와 heightλ₯Ό λͺ¨λ‘ 100%둜 μ§€μ •ν•œ ν›„ object-fit: cover을 μ΄μš©ν•΄ μ΄λ―Έμ§€μ˜ ν•œ 변이 λ‹€λ₯Έ 변에 λΉ„ν•΄ μ‹¬ν•˜κ²Œ 길어도 원에 λ”± 맞게 μœ„μΉ˜ν•˜λ„λ‘ ν–ˆλ‹€.

λ‹€λ§Œ 이 방법은 μ“Έ λ•Œλ§ˆλ‹€ 더 쒋은 방법이 μžˆμ„κΉŒ κ³ λ―Όλœλ‹€. divλ₯Ό μ΄λ ‡κ²Œ μ€‘λ³΅ν•΄μ„œ μ“°λŠ” 게 μ΅œμ„ μ€ 아닐 텐데.

.profile-outer-box {
  width: 60px;
  .profile-inner-box {
    padding-top: 100%;
    overflow: hidden;
    position: relative;
    border-radius: 50%;
    .profile-img {
      width: 100%; // μΆ”κ°€ ❗
      height: 100%; // μΆ”κ°€ ❗
      object-fit: cover; // μΆ”κ°€ ❗
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
  }
}

6) ν”„λ‘œν•„ 이미지가 μ—†λŠ” 경우

처음 νŒ¨μŠ€μ›Œλ“œλ₯Ό μ΄μš©ν•΄ κ°€μž…ν•˜λ©΄ ν”„λ‘œν•„ 이미지가 μ—†λ‹€.
이 κ²½μš°μ— header의 ν”„λ‘œν•„ 이미지λ₯Ό 이λͺ¨μ§€λ‘œ λŒ€μ²΄ν•œλ‹€.
ν”„λ‘œν•„ 확인 νŽ˜μ΄μ§€λ„ 같은 λ°©λ²•μœΌλ‘œ μˆ˜μ •ν–ˆλ‹€.
a νƒœκ·Έλ₯Ό ν•œ 번만 쓰도둝 μˆ˜μ •ν•˜κ³  μ‹Άμ—ˆμœΌλ‚˜ 5) λ•Œλ¬Έμ— κ·Έλ ‡κ²Œ ν•  μˆ˜κ°€ μ—†λ‹€.

if loggedInUser.avatarUrl === undefined
  a(href=`/users/${loggedInUser._id}`)
    span 😁
else
  div.profile-outer-box
    div.profile-inner-box
      a(href=`/users/${loggedInUser._id}`)
        img(src="/" + loggedInUser.avatarUrl).profile-img

✨ 내일 ν•  것

  1. video player λ§Œλ“€κΈ°
profile
λŠ₯λ™μ μœΌλ‘œ μ‚΄μž, ν–‰λ³΅ν•˜κ²ŒπŸ˜

0개의 λŒ“κΈ€