fixing vlad's review comments

This commit is contained in:
Tiago Vasconcelos 2023-03-09 10:00:55 +00:00
parent e18a2ee7eb
commit 448d243838
5 changed files with 63 additions and 73 deletions

View file

@ -33,7 +33,7 @@
:text="[message.msg]"
:sent="message.sender == 'Me'"
:bg-color="message.sender == 'Me' ? 'white' : 'light-green-2'"
:stamp="`${timeFromNow(message.timestamp * 1000)}`"
:stamp="message.timestamp"
size="6"
/>
</q-card-section>

View file

@ -69,7 +69,7 @@ async function chatDialog(path) {
}
messagesMap.set(event.id, {
msg: plaintext,
timestamp: event.created_at,
timestamp: timeFromNow(event.created_at * 1000),
sender: `${mine ? 'Me' : 'Merchant'}`
})
} catch {
@ -107,11 +107,9 @@ async function chatDialog(path) {
let pub = relay.publish(event)
pub.on('ok', () => {
console.debug(`${relay.url} has accepted our event`)
relay.close()
})
pub.on('failed', reason => {
console.debug(`failed to publish to ${relay.url}: ${reason}`)
relay.close()
})
this.newMessage = ''
} catch (e) {
@ -146,59 +144,6 @@ async function chatDialog(path) {
event = await window.nostr.signEvent(event)
}
return event
},
timeFromNow(time) {
// Get timestamps
let unixTime = new Date(time).getTime()
if (!unixTime) return
let now = new Date().getTime()
// Calculate difference
let difference = unixTime / 1000 - now / 1000
// Setup return object
let tfn = {}
// Check if time is in the past, present, or future
tfn.when = 'now'
if (difference > 0) {
tfn.when = 'future'
} else if (difference < -1) {
tfn.when = 'past'
}
// Convert difference to absolute
difference = Math.abs(difference)
// Calculate time unit
if (difference / (60 * 60 * 24 * 365) > 1) {
// Years
tfn.unitOfTime = 'years'
tfn.time = Math.floor(difference / (60 * 60 * 24 * 365))
} else if (difference / (60 * 60 * 24 * 45) > 1) {
// Months
tfn.unitOfTime = 'months'
tfn.time = Math.floor(difference / (60 * 60 * 24 * 45))
} else if (difference / (60 * 60 * 24) > 1) {
// Days
tfn.unitOfTime = 'days'
tfn.time = Math.floor(difference / (60 * 60 * 24))
} else if (difference / (60 * 60) > 1) {
// Hours
tfn.unitOfTime = 'hours'
tfn.time = Math.floor(difference / (60 * 60))
} else if (difference / 60 > 1) {
// Minutes
tfn.unitOfTime = 'minutes'
tfn.time = Math.floor(difference / 60)
} else {
// Seconds
tfn.unitOfTime = 'seconds'
tfn.time = Math.floor(difference)
}
// Return time from now data
return `${tfn.time} ${tfn.unitOfTime}`
}
},
created() {

View file

@ -62,12 +62,13 @@ const market = async () => {
if (this.activeStall) {
products = products.filter(p => p.stall_id == this.activeStall)
}
if (!this.searchText || this.searchText.length < 2) return products
const searchText = this.searchText.toLowerCase()
if (!searchText || searchText.length < 2) return products
return products.filter(p => {
return (
p.name.includes(this.searchText) ||
p.description.includes(this.searchText) ||
p.categories.includes(this.searchText)
p.name.toLowerCase().includes(searchText) ||
p.description.toLowerCase().includes(searchText) ||
p.categories.toLowerCase().includes(searchText)
)
})
},

View file

@ -38,3 +38,57 @@ function isJson(str) {
return false
}
}
function timeFromNow(time) {
// Get timestamps
let unixTime = new Date(time).getTime()
if (!unixTime) return
let now = new Date().getTime()
// Calculate difference
let difference = unixTime / 1000 - now / 1000
// Setup return object
let tfn = {}
// Check if time is in the past, present, or future
tfn.when = 'now'
if (difference > 0) {
tfn.when = 'future'
} else if (difference < -1) {
tfn.when = 'past'
}
// Convert difference to absolute
difference = Math.abs(difference)
// Calculate time unit
if (difference / (60 * 60 * 24 * 365) > 1) {
// Years
tfn.unitOfTime = 'years'
tfn.time = Math.floor(difference / (60 * 60 * 24 * 365))
} else if (difference / (60 * 60 * 24 * 45) > 1) {
// Months
tfn.unitOfTime = 'months'
tfn.time = Math.floor(difference / (60 * 60 * 24 * 45))
} else if (difference / (60 * 60 * 24) > 1) {
// Days
tfn.unitOfTime = 'days'
tfn.time = Math.floor(difference / (60 * 60 * 24))
} else if (difference / (60 * 60) > 1) {
// Hours
tfn.unitOfTime = 'hours'
tfn.time = Math.floor(difference / (60 * 60))
} else if (difference / 60 > 1) {
// Minutes
tfn.unitOfTime = 'minutes'
tfn.time = Math.floor(difference / 60)
} else {
// Seconds
tfn.unitOfTime = 'seconds'
tfn.time = Math.floor(difference)
}
// Return time from now data
return `${tfn.time} ${tfn.unitOfTime}`
}

View file

@ -23,18 +23,8 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
@nostrmarket_ext.get("/market", response_class=HTMLResponse)
async def market(
request: Request,
stall_id: str = Query(None),
product_id: str = Query(None),
merchant_pubkey: str = Query(None),
):
async def market(request: Request):
return nostrmarket_renderer().TemplateResponse(
"nostrmarket/market.html",
{
"request": request,
"stall_id": stall_id,
"product_id": product_id,
"merchant_pubkey": merchant_pubkey,
},
{"request": request},
)