fixing vlad's review comments
This commit is contained in:
parent
cf12ee9287
commit
f9fc52ac52
5 changed files with 63 additions and 73 deletions
|
|
@ -33,7 +33,7 @@
|
||||||
:text="[message.msg]"
|
:text="[message.msg]"
|
||||||
:sent="message.sender == 'Me'"
|
:sent="message.sender == 'Me'"
|
||||||
:bg-color="message.sender == 'Me' ? 'white' : 'light-green-2'"
|
:bg-color="message.sender == 'Me' ? 'white' : 'light-green-2'"
|
||||||
:stamp="`${timeFromNow(message.timestamp * 1000)}`"
|
:stamp="message.timestamp"
|
||||||
size="6"
|
size="6"
|
||||||
/>
|
/>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ async function chatDialog(path) {
|
||||||
}
|
}
|
||||||
messagesMap.set(event.id, {
|
messagesMap.set(event.id, {
|
||||||
msg: plaintext,
|
msg: plaintext,
|
||||||
timestamp: event.created_at,
|
timestamp: timeFromNow(event.created_at * 1000),
|
||||||
sender: `${mine ? 'Me' : 'Merchant'}`
|
sender: `${mine ? 'Me' : 'Merchant'}`
|
||||||
})
|
})
|
||||||
} catch {
|
} catch {
|
||||||
|
|
@ -107,11 +107,9 @@ async function chatDialog(path) {
|
||||||
let pub = relay.publish(event)
|
let pub = relay.publish(event)
|
||||||
pub.on('ok', () => {
|
pub.on('ok', () => {
|
||||||
console.debug(`${relay.url} has accepted our event`)
|
console.debug(`${relay.url} has accepted our event`)
|
||||||
relay.close()
|
|
||||||
})
|
})
|
||||||
pub.on('failed', reason => {
|
pub.on('failed', reason => {
|
||||||
console.debug(`failed to publish to ${relay.url}: ${reason}`)
|
console.debug(`failed to publish to ${relay.url}: ${reason}`)
|
||||||
relay.close()
|
|
||||||
})
|
})
|
||||||
this.newMessage = ''
|
this.newMessage = ''
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -146,59 +144,6 @@ async function chatDialog(path) {
|
||||||
event = await window.nostr.signEvent(event)
|
event = await window.nostr.signEvent(event)
|
||||||
}
|
}
|
||||||
return 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() {
|
created() {
|
||||||
|
|
|
||||||
|
|
@ -62,12 +62,13 @@ const market = async () => {
|
||||||
if (this.activeStall) {
|
if (this.activeStall) {
|
||||||
products = products.filter(p => p.stall_id == 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 products.filter(p => {
|
||||||
return (
|
return (
|
||||||
p.name.includes(this.searchText) ||
|
p.name.toLowerCase().includes(searchText) ||
|
||||||
p.description.includes(this.searchText) ||
|
p.description.toLowerCase().includes(searchText) ||
|
||||||
p.categories.includes(this.searchText)
|
p.categories.toLowerCase().includes(searchText)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -47,3 +47,57 @@ function isJson(str) {
|
||||||
return false
|
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}`
|
||||||
|
}
|
||||||
|
|
|
||||||
14
views.py
14
views.py
|
|
@ -23,18 +23,8 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
|
||||||
|
|
||||||
|
|
||||||
@nostrmarket_ext.get("/market", response_class=HTMLResponse)
|
@nostrmarket_ext.get("/market", response_class=HTMLResponse)
|
||||||
async def market(
|
async def market(request: Request):
|
||||||
request: Request,
|
|
||||||
stall_id: str = Query(None),
|
|
||||||
product_id: str = Query(None),
|
|
||||||
merchant_pubkey: str = Query(None),
|
|
||||||
):
|
|
||||||
return nostrmarket_renderer().TemplateResponse(
|
return nostrmarket_renderer().TemplateResponse(
|
||||||
"nostrmarket/market.html",
|
"nostrmarket/market.html",
|
||||||
{
|
{"request": request},
|
||||||
"request": request,
|
|
||||||
"stall_id": stall_id,
|
|
||||||
"product_id": product_id,
|
|
||||||
"merchant_pubkey": merchant_pubkey,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue