diff --git a/diskuy/src/Threads/CommentList.js b/diskuy/src/Threads/CommentList.js index 8163e4752a6f64f47918e73d6db373e2b8c0e8db..24438c230876e78323543d42087dd6c4f29da47f 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 269d9172911c5a5c5389dd74520191f4fbc8acbf..961ccb0cec864596fa40c88af3f9d5c20c0f4e2d 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 2f61644813c800de81f6bd8a520806e5c3b40370..031ad0b2576746ae535fe7cfbd073bf5ccedd395 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) } @@ -40,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> diff --git a/diskuy/src/helpers/time-util.js b/diskuy/src/helpers/time-util.js index 202b391012f5129c13efbc19c80164421cfa8465..058fe4d5596e2450ae0b0a9eae620cd6475fb546 100644 --- a/diskuy/src/helpers/time-util.js +++ b/diskuy/src/helpers/time-util.js @@ -1,25 +1,31 @@ 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) { - 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}