From 92b4016c765ff1f36dd75057d24017356a45f6c0 Mon Sep 17 00:00:00 2001 From: chaerin <70943835+chaerin-dev@users.noreply.github.com> Date: Sat, 11 Jun 2022 04:42:31 +0900 Subject: [PATCH] vanillaJS -> React --- .DS_Store | Bin 0 -> 6148 bytes README.md | 20 +- Section/Footer/footer.js | 36 --- Section/SearchBox/components/SearchInput.js | 24 -- .../SearchBox/components/SearchableList.js | 49 --- Section/SearchBox/components/index.js | 18 -- Section/SearchBox/utils/api.js | 6 - Section/SearchBox/utils/koreanFuzzy.js | 38 --- Section/SearchResult/components/index.js | 84 ----- Section/SearchResult/utils/api.js | 6 - Section/SearchResult/utils/copyText.js | 11 - app.js | 28 -- index.html | 30 -- public/index.html | 13 +- src/.DS_Store | Bin 0 -> 6148 bytes src/App.js | 17 +- src/Footer/footer.js | 85 +++-- src/Loading.js | 13 + src/SearchBox/.DS_Store | Bin 0 -> 6148 bytes src/SearchBox/SearchBox.js | 13 + src/SearchBox/components/SearchInput.js | 45 +-- src/SearchBox/components/SearchPhrases.js | 11 + src/SearchBox/components/SearchableList.js | 99 +++--- src/SearchBox/components/index.js | 18 -- src/SearchBox/utils/api.js | 10 +- .../SearchBox}/utils/format.js | 6 +- src/SearchResult/SearchResult.js | 48 +++ src/SearchResult/components/index.js | 84 ----- src/SearchResult/utils/api.js | 6 - src/SearchResult/utils/format.js | 10 +- {images => src/images}/favicon-16x16.png | Bin {images => src/images}/favicon-32x32.png | Bin {images => src/images}/favicon.ico | Bin {images => src/images}/github.png | Bin {images => src/images}/programmers.png | Bin {images => src/images}/spinner.svg | 0 src/index.js | 28 +- src/styles/style.css | 304 ++++++++++++++++++ {styles => src/styles}/style.css.map | 0 {styles => src/styles}/style.scss | 150 ++++----- styles/style.css | 227 ------------- 41 files changed, 661 insertions(+), 876 deletions(-) create mode 100644 .DS_Store delete mode 100644 Section/Footer/footer.js delete mode 100644 Section/SearchBox/components/SearchInput.js delete mode 100644 Section/SearchBox/components/SearchableList.js delete mode 100644 Section/SearchBox/components/index.js delete mode 100644 Section/SearchBox/utils/api.js delete mode 100644 Section/SearchBox/utils/koreanFuzzy.js delete mode 100644 Section/SearchResult/components/index.js delete mode 100644 Section/SearchResult/utils/api.js delete mode 100644 Section/SearchResult/utils/copyText.js delete mode 100644 app.js delete mode 100644 index.html create mode 100644 src/.DS_Store create mode 100644 src/Loading.js create mode 100644 src/SearchBox/.DS_Store create mode 100644 src/SearchBox/SearchBox.js create mode 100644 src/SearchBox/components/SearchPhrases.js delete mode 100644 src/SearchBox/components/index.js rename {Section/SearchResult => src/SearchBox}/utils/format.js (52%) create mode 100644 src/SearchResult/SearchResult.js delete mode 100644 src/SearchResult/components/index.js delete mode 100644 src/SearchResult/utils/api.js rename {images => src/images}/favicon-16x16.png (100%) rename {images => src/images}/favicon-32x32.png (100%) rename {images => src/images}/favicon.ico (100%) rename {images => src/images}/github.png (100%) rename {images => src/images}/programmers.png (100%) rename {images => src/images}/spinner.svg (100%) create mode 100644 src/styles/style.css rename {styles => src/styles}/style.css.map (100%) rename {styles => src/styles}/style.scss (73%) delete mode 100644 styles/style.css diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..54d714d756cb3f84b0ced43bd052ee55618c9597 GIT binary patch literal 6148 zcmeHL!A=4(5Pg*uiD<&ni%E}ilRsE-jURv~FCt)&gk_1q!P|a{pW$6j-uMSUzz^`? zOgl!~1-TJ1ouqxGGt+td!nPCusyXX5fEs`bHO6S4x+TVbZUx(snIl4F*0{rD*l)DD zSvoF6hl!v-P~fjA!0&Du1Ejb`AO8DW`WX2BG)t1sFze7fZwjxMC-bvnOmA(>`2NQ} z5ouZi2N)qkk67FgA0EvxEO5fk;-wWi?@!;W>u8S=ZX20 zFu{Yb$o2cT$E&}P`jY3>^}J3!I(^8>RBwvMW#5_eH{b8o{(5$24UfUn7>5Vi%wt>3 zs)kB+TL=f9L4lya#uVWFK~rOl1#^pL>!8kD0SF_SHb!HoX(dg1Bsp6P565S%rq-s$#&NktlR}*w$7aAsG5@b%jC`60gt1_5k!Hxk O4*?@X=z; - - -
-
Contributor
- 김경현 - 김채린 - 손용찬 -
-
해당 페이지의 해답을 자신의 저작물에 추가할 수 있지만 반드시 본 Repository의 주소를 명시하여야합니다.
-
모든 문제의 저작권은 프로그래머스에 있습니다.
- - - `; - - template = template.replaceAll("{{__레포지토리주소__}}", "https://github.com/codeisneverodd/programmers-coding-test") - footer.innerHTML = template; - - } \ No newline at end of file diff --git a/Section/SearchBox/components/SearchInput.js b/Section/SearchBox/components/SearchInput.js deleted file mode 100644 index 1f205ee..0000000 --- a/Section/SearchBox/components/SearchInput.js +++ /dev/null @@ -1,24 +0,0 @@ -import { CreateFuzzyMatcher } from '../utils/koreanFuzzy.js'; - -export function SearchInput() { - this.render = () => { - const $searchInput = document.querySelector('.searchInput'); - $searchInput.innerHTML = ` - - `; - const $fileListItem = document.querySelectorAll('.file-list-item'); - - $searchInput.addEventListener('input', event => { - const $searchInputBox = document.getElementById('searchInput'); - const query = $searchInputBox.value; - const regex = CreateFuzzyMatcher(query.toLowerCase()); - for (let i = 0; i < $fileListItem.length; i++) { - if (regex.test($fileListItem[i].textContent.toLowerCase())) { - $fileListItem[i].classList.remove('is-hidden'); - } else { - $fileListItem[i].classList.add('is-hidden'); - } - } - }); - }; -} diff --git a/Section/SearchBox/components/SearchableList.js b/Section/SearchBox/components/SearchableList.js deleted file mode 100644 index 43898eb..0000000 --- a/Section/SearchBox/components/SearchableList.js +++ /dev/null @@ -1,49 +0,0 @@ -//TODO: api 함수 및 상수 분리 -import SearchResult from '../../SearchResult/components/index.js'; -import { getFileList } from '../utils/api.js'; - -const POSSIBLE_LEVELS = [1, 2, 3, 4, 5]; -export function SearchableList() { - const $searchableList = document.querySelector('.searchableList'); - this.render = async () => { - $searchableList.innerHTML = ` -
- `; - const $fileListContainer = document.querySelector('.file-list-container'); - await fillList(); - async function fillList() { - const fileList = {}; - for (const level of POSSIBLE_LEVELS) { - fileList[level] = await getFileList(level); - delete fileList[level][0]; - } - $fileListContainer.innerHTML = ` - ${POSSIBLE_LEVELS.map( - level => ` -
    -
    [level ${level}]
    - ${fileList[level] - .map( - file => - `
  • ${file.name - .slice(0, file.name.length - 3) - .replaceAll('-', ' ')}
  • `, - ) - .join('')} -
`, - ).join('')} - `; - } - - $fileListContainer.addEventListener('click', e => { - if (e.target.tagName !== 'LI') return; - const level = e.target.parentNode.classList[1].slice(-1); - const fileName = e.target.classList[1]; - const $searchResult = new SearchResult({ - level, - fileName, - }); - $searchResult.render(); - }); - }; -} diff --git a/Section/SearchBox/components/index.js b/Section/SearchBox/components/index.js deleted file mode 100644 index d46ae2c..0000000 --- a/Section/SearchBox/components/index.js +++ /dev/null @@ -1,18 +0,0 @@ -import { SearchInput } from './SearchInput.js'; -import { SearchableList } from './SearchableList.js'; - -export default function SearchBox() { - const $searchBox = document.querySelector('.searchBox'); - this.render = async () => { - $searchBox.innerHTML = ` -
-
- - `; - const searchInput = new SearchInput(); - const searchableList = new SearchableList(); - - await searchableList.render(); - searchInput.render(); - }; -} diff --git a/Section/SearchBox/utils/api.js b/Section/SearchBox/utils/api.js deleted file mode 100644 index ae7e4c6..0000000 --- a/Section/SearchBox/utils/api.js +++ /dev/null @@ -1,6 +0,0 @@ -const GET_FILE_LIST_BASE_URL = `https://api.github.com/repos/codeisneverodd/programmers-coding-test/contents/`; -export const getFileList = async level => { - const url = GET_FILE_LIST_BASE_URL + `level-${level}`; - const response = await fetch(url); - return await response.json(); -}; diff --git a/Section/SearchBox/utils/koreanFuzzy.js b/Section/SearchBox/utils/koreanFuzzy.js deleted file mode 100644 index 8a65ceb..0000000 --- a/Section/SearchBox/utils/koreanFuzzy.js +++ /dev/null @@ -1,38 +0,0 @@ -const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - -const ch2pattern = ch => { - const offset = 44032; - if (/[가-힣]/.test(ch)) { - const chCode = ch.charCodeAt(0) - offset; - if (chCode % 28 > 0) { - return ch; - } - const begin = Math.floor(chCode / 28) * 28 + offset; - const end = begin + 27; - return `[\\u${begin.toString(16)}-\\u${end.toString(16)}]`; - } - if (/[ㄱ-ㅎ]/.test(ch)) { - const con2syl = { - ㄱ: '가'.charCodeAt(0), - ㄲ: '까'.charCodeAt(0), - ㄴ: '나'.charCodeAt(0), - ㄷ: '다'.charCodeAt(0), - ㄸ: '따'.charCodeAt(0), - ㄹ: '라'.charCodeAt(0), - ㅁ: '마'.charCodeAt(0), - ㅂ: '바'.charCodeAt(0), - ㅃ: '빠'.charCodeAt(0), - ㅅ: '사'.charCodeAt(0), - }; - const begin = - con2syl[ch] || (ch.charCodeAt(0) - 12613) * 588 + con2syl['ㅅ']; - const end = begin + 587; - return `[${ch}\\u${begin.toString(16)}-\\u${end.toString(16)}]`; - } - return escapeRegExp(ch); -}; - -export const CreateFuzzyMatcher = input => { - const pattern = input.split('').map(ch2pattern).join('.*?'); - return new RegExp(pattern); -}; diff --git a/Section/SearchResult/components/index.js b/Section/SearchResult/components/index.js deleted file mode 100644 index 9201722..0000000 --- a/Section/SearchResult/components/index.js +++ /dev/null @@ -1,84 +0,0 @@ -import { getFileContent } from "../utils/api.js"; -import { formattedFileName, splitCodeToSolutions } from "../utils/format.js"; -import { copyText } from "../utils/copyText.js"; - -export default function SearchResult({ level, fileName }) { - let page = 0; - this.render = async () => { - const $searchResult = document.querySelector('.searchResult'); - $searchResult.innerHTML = ` -
- - -
-
-
-

-        
-      
- `; - const $fileTitle = document.querySelector('.file-title'); - const $code = document.querySelector('.code'); - const solutions = splitCodeToSolutions( - await getFileContent(level, fileName), - ); - setCurrentResult(); - addCopyEvent(); - addNavEvent(); - - function setCurrentResult() { - $fileTitle.innerHTML = formattedFileName(fileName); - $code.innerHTML = solutions[page]; - if(solutions.length > 1){ - const $btnNextSolution = document.querySelector('.btnNextSolution-inactive') - $btnNextSolution.className = 'btnNextSolution' - } - } - - function addCopyEvent() { - const $copyBtn = document.querySelector('.btn-copy'); - $copyBtn.addEventListener('click', e => { - const src = e.target.previousElementSibling; - copyText(src); - const isCopied = document.querySelector('.isCopied'); - isCopied.textContent = ' 📋 클립보드에 복사됨!'; - setTimeout(() => { - isCopied.textContent = ''; - }, 1000); - }); - } - - function addNavEvent() { - const $navigator = document.querySelector('.solutionNavigator'); - const btnPrevSolution = document.querySelector( - '.btnPrevSolution-inactive', - ); - const btnNextSolution = document.querySelector('.btnNextSolution'); - if (page === 0) { - btnPrevSolution.className = 'btnPrevSolution-inactive'; - } - $navigator.addEventListener('click', e => { - const $clickedButton = e.target.closest('button'); - - if ($clickedButton.className.includes('btnPrevSolution')) { - if (page > 0) { - page -= 1; - $code.innerHTML = solutions[page]; - } - } - if ($clickedButton.className.includes('btnNextSolution')) { - if (page < solutions.length - 1) { - page += 1; - $code.innerHTML = solutions[page]; - } - } - page !== 0 - ? (btnPrevSolution.className = 'btnPrevSolution') - : (btnPrevSolution.className = 'btnPrevSolution-inactive'); - page === solutions.length - 1 - ? (btnNextSolution.className = 'btnNextSolution-inactive') - : (btnNextSolution.className = 'btnNextSolution'); - }); - } - }; -} diff --git a/Section/SearchResult/utils/api.js b/Section/SearchResult/utils/api.js deleted file mode 100644 index e2cdee0..0000000 --- a/Section/SearchResult/utils/api.js +++ /dev/null @@ -1,6 +0,0 @@ -const GET_FILE_CONTENT_BASE_URL = `https://raw.githubusercontent.com/codeisneverodd/programmers-coding-test/main/`; -export const getFileContent = async (level, fileName) => { - const url = GET_FILE_CONTENT_BASE_URL + `/level-${level}` + `/${fileName}`; - const response = await fetch(url); - return await response.text(); -}; diff --git a/Section/SearchResult/utils/copyText.js b/Section/SearchResult/utils/copyText.js deleted file mode 100644 index 67a9637..0000000 --- a/Section/SearchResult/utils/copyText.js +++ /dev/null @@ -1,11 +0,0 @@ -export function copyText(src) { - const t = document.createElement('textarea'); - document.body.appendChild(t); - t.value = src.innerHTML - .replace(/</g, '<') - .replace(/>/g, '>') - .replace(/"/g, '"'); - t.select(); - document.execCommand('copy'); - document.body.removeChild(t); -} diff --git a/app.js b/app.js deleted file mode 100644 index 1335594..0000000 --- a/app.js +++ /dev/null @@ -1,28 +0,0 @@ -import SearchBox from './Section/SearchBox/components/index.js'; -import FooterBox from './Section/Footer/footer.js'; - -const $app = document.querySelector('.app'); -const $loading = document.querySelector('.loading'); - -const init = async () => { - $app.innerHTML = ` - -
-
- `; - const $searchBox = new SearchBox(); - await $searchBox.render(); -}; - -const loading = async () => { - $loading.innerHTML = ` - - - Loading… - `; - await init(); - FooterBox(); - $loading.style.display = 'none'; -}; - -loading(); \ No newline at end of file diff --git a/index.html b/index.html deleted file mode 100644 index 2b57603..0000000 --- a/index.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - 프로그래머스 해설 은행 - - - - - - -

🔍 프로그래머스 해설 은행

-
-
- - - diff --git a/public/index.html b/public/index.html index 0f5f6bc..f3efa95 100644 --- a/public/index.html +++ b/public/index.html @@ -3,24 +3,19 @@ - + 프로그래머스 해설 은행 - + diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1ccffbb52c24f7c308896e9d557ad7c20b49a20d GIT binary patch literal 6148 zcmeHK%}&BV5T2EWfO;UtgU4P?JjfeVQoSoLz@GsUNC|?`TMu5m`8IksJ_(75iLcIJ3wX?IkU%#e1ED@Q;yjLfx5m5z=G1!GGFz)A;vmF;X1R6WXHBCqT zdb691C%J45r~<0MUsHg;-7;NJg5QjC-*5FG+dod?xHC#Ri1Vg!xj241%jfjA=1c~w z`vmVl;4!2zwW$vtH{L!{`Wj~YGdylzmONJG7$+W&!W@rB5HgP{HNl`wQ|i)y8c^oW zV?!ss;w+z2`uQQ83g+{fZOZic(G&CA_xN40S~RB-&3u-X$4$8zuCMRHb?w|4##{4! z-lxpF44yN(2h;5PrRX8s@AIR@^YZfmF zKZIzEk;7EbZXIy;2mlNawuWn4%Yh*WfRV#g5D}P>p+FgG+!4dbaKuBG7dcD?WjGnT zGUjnB8+Sr6c6G!iKVN_T_Xp{nDxeDdD+NptH{%8#$<@}} w!*Q(*(OPJ1oR +
+

🔍 프로그래머스 해설 은행

+ + + +
+
); } - -export default App; diff --git a/src/Footer/footer.js b/src/Footer/footer.js index ef4d0db..e09633d 100644 --- a/src/Footer/footer.js +++ b/src/Footer/footer.js @@ -1,36 +1,63 @@ -export default function Footer() { - const footer = document.querySelector("#footerBox"); +import gitHubLogoPath from "../images/github.png"; +import programmersLogoPath from "../images/programmers.png"; - let template = ` -