From 91c7aa741dc9456331eaf1f8f8eaaffbb01e4c48 Mon Sep 17 00:00:00 2001
From: FadhilP <fadhilpradipta0@gmail.com>
Date: Sat, 9 Jan 2021 18:07:25 +0700
Subject: [PATCH 1/4] add error handling on time-util

---
 diskuy/src/helpers/time-util.js | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/diskuy/src/helpers/time-util.js b/diskuy/src/helpers/time-util.js
index 202b391..d84fd8a 100644
--- a/diskuy/src/helpers/time-util.js
+++ b/diskuy/src/helpers/time-util.js
@@ -1,16 +1,19 @@
 const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September","October", "November", "December"];
 
 function tConvert (time) {
-    // Check correct time format and split into components
-    time = time.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time];
-  
-    if (time.length > 1) { // If time format correct
-        console.log(time)
-        time = time.slice (1, 4);  // Remove full string match value
-        time[5] = +time[0] < 12 ? ' AM' : ' PM'; // Set AM/PM
-        time[0] = +time[0] % 12 || 12; // Adjust hours
-    }
-    return time.join (''); // return adjusted time or original string
+    try{
+        // Check correct time format and split into components
+        time = time.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time];
+    
+        if (time.length > 1) { // If time format correct
+            console.log(time)
+            time = time.slice (1, 4);  // Remove full string match value
+            time[5] = +time[0] < 12 ? ' AM' : ' PM'; // Set AM/PM
+            time[0] = +time[0] % 12 || 12; // Adjust hours
+        }
+        return time.join (''); // return adjusted time or original string
+    } catch(error){}
+    
 }
 
 function translate(time) {
-- 
GitLab


From bd27a81365e38d34c2c65d49dbcd416300eac804 Mon Sep 17 00:00:00 2001
From: FadhilP <fadhilpradipta0@gmail.com>
Date: Sat, 9 Jan 2021 18:07:44 +0700
Subject: [PATCH 2/4] sort threads in topics by id's

---
 diskuy/src/Topic.js | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/diskuy/src/Topic.js b/diskuy/src/Topic.js
index 2f61644..a2f7e27 100644
--- a/diskuy/src/Topic.js
+++ b/diskuy/src/Topic.js
@@ -18,7 +18,12 @@ export default function Topic(props){
            
             const topic = responseTopics.data.data.find(topic => topic.name === topicParam).id
             const threads = responseThreads.data.data.filter(thread => thread.topic_id === topic)
-            setThread(threads)
+            const sortedThreads = threads.sort((a, b) => {
+                if (a.id < b.id) return 1
+                if (a.id > b.id) return -1
+                return 0
+            })
+            setThread(sortedThreads)
             console.log(threads)
             
         }
-- 
GitLab


From 157c1e0cb82ecf2708173dc4c5643cb5d840cf62 Mon Sep 17 00:00:00 2001
From: FadhilP <fadhilpradipta0@gmail.com>
Date: Sat, 9 Jan 2021 18:16:37 +0700
Subject: [PATCH 3/4] fix get current date function

---
 diskuy/src/helpers/time-util.js | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/diskuy/src/helpers/time-util.js b/diskuy/src/helpers/time-util.js
index d84fd8a..058fe4d 100644
--- a/diskuy/src/helpers/time-util.js
+++ b/diskuy/src/helpers/time-util.js
@@ -17,12 +17,15 @@ function tConvert (time) {
 }
 
 function translate(time) {
-    const timeSplit = time.split('T')
-    const date = new Date(timeSplit[0])
+    try {  
+        const timeSplit = time.split('T')
+        const date = new Date(timeSplit[0])
+        
+        const fullDate = `${date.getDate()} ${monthNames[date.getMonth()]} ${date.getFullYear()}`
     
-    const fullDate = `${date.getDay()} ${monthNames[date.getMonth()]} ${date.getFullYear()}`
-
-    return `${fullDate}, ${tConvert(timeSplit[1])}`
+        return `${fullDate}, ${tConvert(timeSplit[1])}`
+    } catch(error){}
+   
 }
 
 export {tConvert, translate}
-- 
GitLab


From 706f5ed7f1f623e4a487a3f85f910133ce4fabc6 Mon Sep 17 00:00:00 2001
From: FadhilP <fadhilpradipta0@gmail.com>
Date: Sat, 9 Jan 2021 18:17:25 +0700
Subject: [PATCH 4/4] change time props to inserted_at

---
 diskuy/src/Threads/CommentList.js | 2 +-
 diskuy/src/Threads/Thread.js      | 2 +-
 diskuy/src/Topic.js               | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/diskuy/src/Threads/CommentList.js b/diskuy/src/Threads/CommentList.js
index 8163e47..24438c2 100644
--- a/diskuy/src/Threads/CommentList.js
+++ b/diskuy/src/Threads/CommentList.js
@@ -14,7 +14,7 @@ export default function CommentList(props){
                         user_id={value.user_id}
                         thread_id={value.thread_id}
                         topic_id={value.topic_id}
-                        time={value.updated_at}/>
+                        time={value.inserted_at}/>
                 </div>
             ))}
         </div>
diff --git a/diskuy/src/Threads/Thread.js b/diskuy/src/Threads/Thread.js
index 269d917..961ccb0 100644
--- a/diskuy/src/Threads/Thread.js
+++ b/diskuy/src/Threads/Thread.js
@@ -100,7 +100,7 @@ export default function Thread(props){
                     user_id={thread.user_id}
                     thread_id={thread.thread_id}
                     topic_id={thread.topic_id}
-                    time={thread.updated_at}
+                    time={thread.inserted_at}
                     redirect={redirect}
                 />
             </div>
diff --git a/diskuy/src/Topic.js b/diskuy/src/Topic.js
index a2f7e27..031ad0b 100644
--- a/diskuy/src/Topic.js
+++ b/diskuy/src/Topic.js
@@ -45,7 +45,7 @@ export default function Topic(props){
                             header={value.title}
                             user={value.username}
                             points={value.points}
-                            time={value.updated_at}
+                            time={value.inserted_at}
                             topic={value.topic_name}>
                         </ThreadList>
                     </Link>
-- 
GitLab