From 4c2e2aa2138a69930936034cfcf9d0ca65dba531 Mon Sep 17 00:00:00 2001 From: sejung1997 Date: Mon, 20 Jun 2022 02:57:00 +0900 Subject: [PATCH 1/2] enhancement/#4/setting --- src/api/getSearchData.js | 17 ---------- .../challenge/api/getChallengeData.js | 14 ++++++++ src/pages/challenge/list/index.js | 32 ++++++++++++++++++- 3 files changed, 45 insertions(+), 18 deletions(-) delete mode 100644 src/api/getSearchData.js create mode 100644 src/component/challenge/api/getChallengeData.js diff --git a/src/api/getSearchData.js b/src/api/getSearchData.js deleted file mode 100644 index 499a477..0000000 --- a/src/api/getSearchData.js +++ /dev/null @@ -1,17 +0,0 @@ -const baseUrl = - "https://wr4a6p937i.execute-api.ap-northeast-2.amazonaws.com/dev"; - -// const cache = {}; -export const getSearchData = async (keywords) => { - // if (cache[keywords]) { - // console.log("zzzz"); - // return cache[keywords]; - // } - const res = await fetch(`${baseUrl}/languages?keyword=${keywords}`); - if (res.ok) { - const json = await res.json(); - // cache[keywords] = json; - return json; - } - throw new Error("요청에 실패함"); -}; diff --git a/src/component/challenge/api/getChallengeData.js b/src/component/challenge/api/getChallengeData.js new file mode 100644 index 0000000..1b16baf --- /dev/null +++ b/src/component/challenge/api/getChallengeData.js @@ -0,0 +1,14 @@ +const baseUrl = + "https://backend.ddudutodo.site/api/v1/challenges"; + +// const cache = {}; +export const getData = async (keywords) => { + + const res = await fetch(`${baseUrl}/`); + if (res.ok) { + const json = await res.json(); + // cache[keywords] = json; + return json; + } + throw new Error("요청에 실패함"); +}; diff --git a/src/pages/challenge/list/index.js b/src/pages/challenge/list/index.js index 267e227..5a11e4e 100644 --- a/src/pages/challenge/list/index.js +++ b/src/pages/challenge/list/index.js @@ -1 +1,31 @@ -export default function CallengeListPage() {} +import {getData} from "../../../../src/component/challenge/api/getChallengeData" +export default function ChallengeList () { + const target = document.querySelector(".App") + const element = document.createElement("div") + let state = + [ + { + "name": "string", + "contents": "string", + "image": "string", + "start_date": "2022-06-19T09:19:42.168000+00:00", + "end_date": "2022-06-19T09:19:42.168000+00:00", + "tags": [ + "string" + ], + "id": 1 + } + ] + state = await getData(0) + + const render = () => { + element.innerHTML = ` +

내 첼린지

+ Date: Fri, 24 Jun 2022 23:50:35 +0900 Subject: [PATCH 2/2] enhancement/#4/setting --- index.html | 2 +- .../challenge/api/getChallengeData.js | 129 ++++++++++++++++-- src/index.js | 9 +- src/pages/challenge/list/index.js | 55 ++++---- 4 files changed, 157 insertions(+), 38 deletions(-) diff --git a/index.html b/index.html index 1e64bdc..aa0aa2a 100644 --- a/index.html +++ b/index.html @@ -1,6 +1,6 @@ - 2022 FE 데브매칭 + 뚜두투두 diff --git a/src/component/challenge/api/getChallengeData.js b/src/component/challenge/api/getChallengeData.js index 1b16baf..22451cb 100644 --- a/src/component/challenge/api/getChallengeData.js +++ b/src/component/challenge/api/getChallengeData.js @@ -1,14 +1,121 @@ -const baseUrl = - "https://backend.ddudutodo.site/api/v1/challenges"; +const baseUrl = "https://backend.ddudutodo.site/api/v1/challenges"; -// const cache = {}; -export const getData = async (keywords) => { - - const res = await fetch(`${baseUrl}/`); - if (res.ok) { - const json = await res.json(); - // cache[keywords] = json; - return json; - } +const cache = [ + { + name: "자전거로 출근", + contents: "string", + image: "string", + start_date: "2022-06-24T08:01:31.122Z", + end_date: "2022-06-24T08:01:31.122Z", + tags: ["깃생살기", "습관 만들기", "운동", "성별무관"], + master: { + email: "user@example.com", + name: "abc", + nick_name: "def", + picture: "string", + id: 0, + complete_rate: 0, + }, + id: 0, + user_cnt: 15, + }, + { + name: "자전거로 출근", + contents: "string", + image: "string", + start_date: "2022-06-24T08:01:31.122Z", + end_date: "2022-06-24T08:01:31.122Z", + tags: ["깃생살기", "습관 만들기", "운동", "성별무관"], + master: { + email: "user@example.com", + name: "abc", + nick_name: "def", + picture: "string", + id: 0, + complete_rate: 0, + }, + id: 0, + user_cnt: 15, + }, + { + name: "자전거로 출근", + contents: "string", + image: "string", + start_date: "2022-06-24T08:01:31.122Z", + end_date: "2022-06-24T08:01:31.122Z", + tags: ["깃생살기", "습관 만들기", "운동", "성별무관"], + master: { + email: "user@example.com", + name: "abc", + nick_name: "def", + picture: "string", + id: 0, + complete_rate: 0, + }, + id: 0, + user_cnt: 15, + }, + { + name: "자전거로 출근", + contents: "string", + image: "string", + start_date: "2022-06-24T08:01:31.122Z", + end_date: "2022-06-24T08:01:31.122Z", + tags: ["깃생살기", "습관 만들기", "운동", "성별무관"], + master: { + email: "user@example.com", + name: "abc", + nick_name: "def", + picture: "string", + id: 0, + complete_rate: 0, + }, + id: 0, + user_cnt: 15, + }, + { + name: "자전거로 출근", + contents: "string", + image: "string", + start_date: "2022-06-24T08:01:31.122Z", + end_date: "2022-06-24T08:01:31.122Z", + tags: ["깃생살기", "습관 만들기", "운동", "성별무관"], + master: { + email: "user@example.com", + name: "abc", + nick_name: "def", + picture: "string", + id: 0, + complete_rate: 0, + }, + id: 0, + user_cnt: 15, + }, + { + name: "자전거로 출근", + contents: "string", + image: "string", + start_date: "2022-06-24T08:01:31.122Z", + end_date: "2022-06-24T08:01:31.122Z", + tags: ["깃생살기", "습관 만들기", "운동", "성별무관"], + master: { + email: "user@example.com", + name: "abc", + nick_name: "def", + picture: "string", + id: 0, + complete_rate: 0, + }, + id: 0, + user_cnt: 15, + }, +]; +export const getData = async () => { + if (cache) return cache; + // const res = await fetch(`${baseUrl}/`); + // if (res.ok) { + // const json = await res.json(); + // return json; + // } throw new Error("요청에 실패함"); }; diff --git a/src/index.js b/src/index.js index 1aeb661..56b1234 100644 --- a/src/index.js +++ b/src/index.js @@ -1 +1,8 @@ -console.log(location); +import ChallengeList from "./pages/challenge/list/index.js"; + +export default function Test() { + const target = document.querySelector(".App"); + + ChallengeList(target); +} +Test(); diff --git a/src/pages/challenge/list/index.js b/src/pages/challenge/list/index.js index 5a11e4e..d5d6bab 100644 --- a/src/pages/challenge/list/index.js +++ b/src/pages/challenge/list/index.js @@ -1,31 +1,36 @@ -import {getData} from "../../../../src/component/challenge/api/getChallengeData" -export default function ChallengeList () { - const target = document.querySelector(".App") - const element = document.createElement("div") - let state = - [ - { - "name": "string", - "contents": "string", - "image": "string", - "start_date": "2022-06-19T09:19:42.168000+00:00", - "end_date": "2022-06-19T09:19:42.168000+00:00", - "tags": [ - "string" - ], - "id": 1 - } - ] - state = await getData(0) +import { getData } from "../../../../src/component/challenge/api/getChallengeData.js"; +export default function ChallengeList($target) { + const element = document.createElement("div"); + $target?.appendChild(element); + let state = []; + (async function getList() { + state = await getData(0); + render(); + })(); const render = () => { element.innerHTML = `

내 첼린지

` +
  • +
    ${el.name}
    + 마스터: ${el.master.name}
    + +
    + ${el.tags.map( + (tagEl) => ` +
    ${tagEl}
    + ` + )} +
    ${el.price}원~
    +
    +
  • ` - } - render() -} \ No newline at end of file + )} + + + `; + }; +}