Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ window.app = Vue.createApp({
},
created: async function () {
await this.getMerchant()
this.activeTab = await window.determineActiveTab(this)
await this.checkNostrStatus()
setInterval(async () => {
if (
Expand Down
79 changes: 79 additions & 0 deletions static/js/smart-navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Smart Tab Navigation
* Determines the most relevant tab based on merchant setup status
*/

async function determineActiveTab(app) {
// No merchant → Merchant tab
if (!app.merchant || !app.merchant.id) {
return 'merchant'
}

try {
// Check for shipping zones
const {data: zones} = await LNbits.api.request(
'GET',
'/nostrmarket/api/v1/zone',
app.g.user.wallets[0].inkey
)

// Merchant but no zones → Shipping tab
if (!zones || zones.length === 0) {
app.$q.notify({
timeout: 5000,
type: 'info',
message: 'Set up shipping zones to get started'
})
return 'shipping'
}

// Check for stalls
const {data: stalls} = await LNbits.api.request(
'GET',
'/nostrmarket/api/v1/stall?pending=false',
app.g.user.wallets[0].inkey
)

// Zones but no stalls → Stalls tab
if (!stalls || stalls.length === 0) {
app.$q.notify({
timeout: 5000,
type: 'info',
message: 'Create a stall to start selling'
})
return 'stalls'
}

// Check for products across all stalls
let hasProducts = false
for (const stall of stalls) {
const {data: products} = await LNbits.api.request(
'GET',
`/nostrmarket/api/v1/stall/product/${stall.id}?pending=false`,
app.g.user.wallets[0].inkey
)
if (products && products.length > 0) {
hasProducts = true
break
}
}

// Stalls but no products → Products tab
if (!hasProducts) {
app.$q.notify({
timeout: 5000,
type: 'info',
message: 'Add products to your stall'
})
return 'products'
}

// Products exist → Orders tab
return 'orders'
} catch (error) {
console.warn('Error determining active tab:', error)
return 'merchant'
}
}

window.determineActiveTab = determineActiveTab
1 change: 1 addition & 0 deletions templates/nostrmarket/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@

<script src="{{ url_for('nostrmarket_static', path='js/nostr.bundle.js') }}"></script>
<script src="{{ url_for('nostrmarket_static', path='js/utils.js') }}"></script>
<script src="{{ url_for('nostrmarket_static', path='js/smart-navigation.js') }}"></script>
<script src="{{ url_for('nostrmarket_static', path='js/index.js') }}"></script>

<script src="{{ static_url_for('nostrmarket/static', 'components/key-pair.js') }}"></script>
Expand Down