From aa8e2b79449b864e7ff6598f511a663986739ea0 Mon Sep 17 00:00:00 2001 From: tu2463 <117417955+tu2463@users.noreply.github.com> Date: Mon, 4 Dec 2023 23:30:51 -0500 Subject: [PATCH] progress in collection js --- .DS_Store | Bin 10244 -> 10244 bytes final-project/.DS_Store | Bin 6148 -> 6148 bytes final-project/collection.html | 1 + final-project/css/collection.css | 4 +- final-project/img/.DS_Store | Bin 6148 -> 6148 bytes final-project/js/app.js | 24 ++-------- final-project/js/collection-general.js | 61 +++++++++++++++++++++++++ final-project/js/storage.js | 27 ----------- 8 files changed, 68 insertions(+), 49 deletions(-) create mode 100644 final-project/js/collection-general.js diff --git a/.DS_Store b/.DS_Store index b44ff30fd411613dcef6b6c1d41e0b6ab852a8bd..03d572e806a3a0cce096bf0381c0d6222b3afe55 100644 GIT binary patch delta 177 zcmZn(XbG6$&uFqSU^hRb$z~n_Yo^Ie5~*yKIts?-29t9o>?eN|a$+=?93v{v$T7J_ zG=ramGhRTVy4up*P)EVg+-UM=(MUmqoOHwB@&dve`hGnHd12U@oHo delta 70 zcmZn(XbG6$RCU^hRb-ew*FYbHka$sR({q8yy@0ut5LmL?WD3dSa8wK@vbmPV6z a2vu)p5oPAySa6YXGrPhsmd%&Mn3(~wDHIC; diff --git a/final-project/.DS_Store b/final-project/.DS_Store index 2b538b695c7718284ee03acd8c4d7f6326cc19d1..12207d5cd76dbcaccdfa314cde0c7f532d79906e 100644 GIT binary patch delta 522 zcmZ`$y=nqM7@XTRVo@k<-(hLOP4srOB~<`hbw)9wASX z%GOS-%-mvhU2tLH+ufP@X6IWp7L5;I6pHD@Ps7?x34jAs5O>;9+~%p0{mL&{&mSZ@ zNRZq{$4B0_xWk=ZfVvW^`31Uo!2=#KwXokNmi0Ay7!e&{N=A>I1T$TQc;ej<(W!z{ zwG`aFf`Ol#_MCT%AW3+|*pl5^D4*tIes@Mg0iJ0xz?jBj^tC<40HdYZ5zRc2&;LYN zO9~9pKW<ivvonMO`(;QvFEpuBaP!wb3(8bPfkLl>`R%Wc1hfm~`@%UAkqLljb}( RQkA`y%RviLk==Vs`3EvFkX`@) delta 102 zcmZoMXfc=|#>B)qu~2NHo}wrV0|Nsi1A_oVaY0f}eiD$kBdK6x;c`YsmdQpe&nNq` zsW5U(j$(;s + diff --git a/final-project/css/collection.css b/final-project/css/collection.css index a8bbd3cc62..c736a2e528 100644 --- a/final-project/css/collection.css +++ b/final-project/css/collection.css @@ -38,7 +38,7 @@ header { box-sizing: border-box; padding: 7px 15px; border: 7px solid #e9d5ca; - border-radius: 15px; + border-radius: 21px; background: rgba(233, 213, 202, 0.5); width: 100%; height: 395px; @@ -48,7 +48,7 @@ header { } .collected-time { - margin-top: 10px; + margin-top: 17px; font-size: 18px; color: rgba(233, 213, 202, 0.5); } \ No newline at end of file diff --git a/final-project/img/.DS_Store b/final-project/img/.DS_Store index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..89abd18e485ab5db51e1062a20b633e846a598df 100644 GIT binary patch literal 6148 zcmeHKOHRWu5FJA$`ca{PKx~k5f=cBCp(+d3901Z#XhmqMevsH@&mFh|=VJwL#s=l* zEkZCOji2lIjXf{59TSlmZf*xeJtAtt85?aBHO9}`E4JlYx4X;4htKK$GD+icl8(XSP2(Ki{}4lssDmiX zyOW5I9@bll)dnNQo-qS^QqM7`B~APM`3K0-^z zjKEvhk12}h89QKXyjil^`QC?!yM)q_u(kvl#09S-_mY zVdyZkh$k>(sX$9L?uub79qobZ7dp%=S~?kb`7mx|<8CNMMo0WWx|0blYN-mS0!0P3 z?av;c{}=xIf03lWQ~_1sPbpv;qpQ&nDY>(?k{qA40sIEe#{DvjLP6nAjHu~2NHo+1YW5HK<@2y7PQ5M$Y_z%h$?Gdl-A2T%b}u84%9H(hI5x+KtY8KJ$3PAT diff --git a/final-project/js/app.js b/final-project/js/app.js index c940121da8..815097109a 100644 --- a/final-project/js/app.js +++ b/final-project/js/app.js @@ -58,8 +58,7 @@ function endTreasureToCollection() { const curRecord = retrieveHistory(); submitNoteBody(curRecord.startTime, curRecord.duration, curRecord.isCompleted, curRecord.productivity); submitTreasure(); - // window.location.replace("collection.html"); - console.log("go to collection"); + window.location.replace("collection.html"); } function endToEndTreasure() { @@ -93,21 +92,6 @@ else if (curPage == 'end-treasure.html') { const btnTreasure = document.querySelector('.treasure'); btnTreasure.addEventListener('click', () => (endTreasureToCollection())); } - -// Treasure -class Treasure { - constructor(id, category, title, body) { - this.id = id; - this.category = category; - this.title = title; - this.content = body; - this.read = false; - } -} - -const treasures = { - 1: {category: "c_1", title: "t_1", body: "b_1"}, - 2: {category: "c_2", title: "t_2", body: "b_2"} -}; - -const collections = []; \ No newline at end of file +else if (curPage == 'collection.html'){ + updateCollectionInfo(); +} \ No newline at end of file diff --git a/final-project/js/collection-general.js b/final-project/js/collection-general.js new file mode 100644 index 0000000000..cd53d1ca9f --- /dev/null +++ b/final-project/js/collection-general.js @@ -0,0 +1,61 @@ +// Treasure +class Treasure { + constructor(id, category, title, body, read, date) { + this.id = id; + this.category = category; + this.title = title; + this.content = body; + this.read = read; + this.date = date; + } + } + +const treasures = { + 1: {category: "c_1", title: "t_1", body: "b_1"}, + 2: {category: "c_2", title: "t_2", body: "b_2"} + }; + +const collections = []; + +function submitTreasure() { + // get a random treasure from the full treasure catalog + const id = Math.floor(Math.random() * (Object.keys(treasures).length - 1) + 1); // min = 0*l+1 = 1; max = 1*l+1 = l+1 + const t = treasures[id]; + // console.log(Object.keys(treasures).length, id, treasures, t, collections); + const category = t.category; + const title = t.title; + const body = t.body; + + const date = new Date() + const treasure = new Treasure(id, category, title, body, false, date); + collections.push(treasure); + localStorage.setItem('05430FP_curTreasure', id); + + const collectionsArray = Array.from(collections); + console.log(collections); + + const collectionsArrayString = JSON.stringify(collectionsArray); + localStorage.setItem('05430FP_storedCollections', collectionsArrayString); + window.location.replace("end-treasure.html?page=read"); + } + +// collection.html +function updateCollectionInfo() { + // retrieve collections from storage + const collectionsArrayString = localStorage.getItem('05430FP_storedCollections'); + const collectionsArray = JSON.parse(collectionsArrayString); + console.log(collectionsArray); + + // re-add treasures to collections + for (const treasure of collectionsArray) { + const thisTreasure = new Treasure(treasure.id, treasure.category, + treasure.title, treasure.body, treasure.read, treasure.date); + collections.push(thisTreasure); + makeTreasureClone(thisTreasure); + } + console.log(collections); + } + +function makeTreasureClone(thisTreasure){ + console.log("cloning..."); + } diff --git a/final-project/js/storage.js b/final-project/js/storage.js index e3cb19e9fc..3b24f66227 100644 --- a/final-project/js/storage.js +++ b/final-project/js/storage.js @@ -19,14 +19,6 @@ function updateEndInfo() { minElement.innerText = curRecord.duration + " min"; } -function updateEndTreasureInfo() { - const id = localStorage.getItem('05430_curTreasure'); - const t = collections[id]; - const title = t.title; - const body = t.body; - // const titleElement = -} - function retrieveHistory(){ const historyArray = retrieveFromLocalStorage(); const curRecordData = historyArray.slice(-1)[0]; @@ -83,25 +75,6 @@ function submitProductivity() { window.location.replace("end-treasure.html"); } -function submitTreasure() { - const id = Math.floor(Math.random() * (Object.keys(treasures).length - 1) + 1); // min = 0*l+1 = 1; max = 1*l+1 = l+1 - const t = treasures[id]; - console.log(Object.keys(treasures).length, id, treasures, t, collections); - const category = t.category; - const title = t.title; - const body = t.body; - const treasure = new Treasure(id, category, title, body); - collections.push(treasure); - localStorage.setItem('05430FP_curTreasure', id); - - const collectionsArray = Array.from(collections); - console.log(collections); - - const collectionsArrayString = JSON.stringify(collectionsArray); - localStorage.setItem('05430FP_storedCollections', collectionsArrayString); - window.location.replace("end-treasure.html?page=read"); -} - function saveToLocalStorage() { const historyArray = Array.from(history);