display date of the event instead of date of the creation of iCal file
This commit is contained in:
parent
ddbf307c29
commit
ca14709309
|
@ -17,13 +17,31 @@
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parseStartTimeFromiCalString = (text = '') => {
|
||||||
|
const [ dateStr, timeStr ] = text.split('T')
|
||||||
|
const rawDate = dateStr || ''
|
||||||
|
const rawTime = timeStr || ''
|
||||||
|
|
||||||
|
const year = Number(rawDate.slice(0, 4))
|
||||||
|
const month = Number(Math.max(rawDate.slice(4, 6) - 1), 0)
|
||||||
|
const date = Number(rawDate.slice(6, 8))
|
||||||
|
const hour = Number(rawTime.slice(0, 2))
|
||||||
|
const minutes = Number(rawTime.slice(2, 4))
|
||||||
|
const seconds = Number(rawTime.slice(4, 6))
|
||||||
|
|
||||||
|
const parsedDate = new Date(year, month, date, hour, minutes, seconds)
|
||||||
|
return parsedDate.toString()
|
||||||
|
}
|
||||||
|
|
||||||
const migrateRecord = (record) => {
|
const migrateRecord = (record) => {
|
||||||
// NOTE: v2 records
|
// NOTE: v3 records
|
||||||
const id = record.id || record.order
|
const id = record.id || record.order
|
||||||
|
const startTime = record.startTime || null
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...record,
|
...record,
|
||||||
id,
|
id,
|
||||||
|
startTime,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +70,7 @@
|
||||||
localStorage.setItem('fb-to-ical-events', encodedStorage)
|
localStorage.setItem('fb-to-ical-events', encodedStorage)
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveRecord = (id, link, createdAt, title) => {
|
const saveRecord = ({ id, link, createdAt, startTime, title }) => {
|
||||||
if (!useStorage) {
|
if (!useStorage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -64,6 +82,7 @@
|
||||||
id,
|
id,
|
||||||
link,
|
link,
|
||||||
createdAt: createdAt.toString(),
|
createdAt: createdAt.toString(),
|
||||||
|
startTime: startTime.toString(),
|
||||||
title,
|
title,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,14 +124,15 @@
|
||||||
row.remove()
|
row.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
const insertTableRow = ({ id, link, createdAt, title }) => {
|
const insertTableRow = ({ id, link, createdAt, startTime, title }) => {
|
||||||
showTable()
|
showTable()
|
||||||
|
|
||||||
const newRow = document.createElement('tr')
|
const newRow = document.createElement('tr')
|
||||||
|
|
||||||
const createdAtCol = document.createElement('td')
|
const startTimeCol = document.createElement('td')
|
||||||
const parsedCreatedAt = new Date(createdAt)
|
startTimeCol.innerText = startTime ?
|
||||||
createdAtCol.innerText = (parsedCreatedAt || new Date()).toLocaleString()
|
new Date(startTime).toLocaleString() :
|
||||||
|
'N/A\xa0\xa0\xa0\xa0\xa0'
|
||||||
|
|
||||||
const titleCol = document.createElement('td')
|
const titleCol = document.createElement('td')
|
||||||
titleCol.innerText = title
|
titleCol.innerText = title
|
||||||
|
@ -135,23 +155,30 @@
|
||||||
actionCol.appendChild(downloadEl)
|
actionCol.appendChild(downloadEl)
|
||||||
actionCol.appendChild(deleteEl)
|
actionCol.appendChild(deleteEl)
|
||||||
|
|
||||||
newRow.appendChild(createdAtCol)
|
newRow.appendChild(startTimeCol)
|
||||||
newRow.appendChild(titleCol)
|
newRow.appendChild(titleCol)
|
||||||
newRow.appendChild(actionCol)
|
newRow.appendChild(actionCol)
|
||||||
|
|
||||||
tableBody.prepend(newRow)
|
tableBody.prepend(newRow)
|
||||||
}
|
}
|
||||||
|
|
||||||
const createRecord = (uri, summary) => {
|
const createRecord = (uri, summary, startTime) => {
|
||||||
const id = uuidv4()
|
const id = uuidv4()
|
||||||
const createdAt = new Date()
|
const createdAt = new Date()
|
||||||
|
|
||||||
saveRecord(id, uri, createdAt, summary)
|
saveRecord({
|
||||||
|
id,
|
||||||
|
link: uri,
|
||||||
|
createdAt,
|
||||||
|
startTime,
|
||||||
|
title: summary,
|
||||||
|
})
|
||||||
insertTableRow({
|
insertTableRow({
|
||||||
id,
|
id,
|
||||||
link: uri,
|
link: uri,
|
||||||
createdAt,
|
createdAt,
|
||||||
title: summary,
|
title: summary,
|
||||||
|
startTime
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,8 +383,13 @@
|
||||||
|
|
||||||
const summaryMatch = text.match(/SUMMARY:.*/)[0]
|
const summaryMatch = text.match(/SUMMARY:.*/)[0]
|
||||||
const summary = summaryMatch ? summaryMatch.replace(/SUMMARY:/, '') : ''
|
const summary = summaryMatch ? summaryMatch.replace(/SUMMARY:/, '') : ''
|
||||||
|
const startTimeMatches = text.match(/DTSTART:.*/)
|
||||||
|
const startTimeMatch = text.length > 0 ?
|
||||||
|
(startTimeMatches[0] || '').replace(/DTSTART:/, '') :
|
||||||
|
''
|
||||||
|
const startTime = parseStartTimeFromiCalString(startTimeMatch)
|
||||||
|
|
||||||
createRecord(uri, summary)
|
createRecord(uri, summary, startTime)
|
||||||
clearStatuses()
|
clearStatuses()
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|
|
@ -87,6 +87,7 @@ input {
|
||||||
}
|
}
|
||||||
|
|
||||||
#list {
|
#list {
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.row {
|
.row {
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
<table id="list" class="hidden">
|
<table id="list" class="hidden">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Created at</td>
|
<td>Date</td>
|
||||||
<td>Title</td>
|
<td>Title</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
Loading…
Reference in New Issue