Skip to content

Commit

Permalink
feat(nuxt3): add settings to home page
Browse files Browse the repository at this point in the history
  • Loading branch information
LarchLiu committed Jan 26, 2024
1 parent 0756cc2 commit 5b452ec
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions server/nuxt3/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const cardHeight = 246
type LoadMoreStatus = 'idle' | 'loading' | 'no-more' | 'error'

const runtimeConfig = useRuntimeConfig()
const _userId = useLocalStorage('userId', '')
const userId = useLocalStorage('userId', '')
const { width: windowWidth, height: windowHeight } = useWindowSize()
const pageSize = computed(() => {
return Math.floor(windowWidth.value / cardWidth) * 10
Expand All @@ -21,12 +21,12 @@ async function getDataList() {

const body = page.value
? {
userId: _userId.value,
userId: userId.value,
pageSize: pageSize.value,
page: page.value,
}
: {
userId: _userId.value,
userId: userId.value,
pageSize: pageSize.value,
}
try {
Expand Down Expand Up @@ -124,14 +124,14 @@ function configurePushSubscription() {
}
})
.then((pushSubscription) => {
console.log('subscription !!!', { ...JSON.parse(JSON.stringify(pushSubscription)), userId: _userId.value })
console.log('subscription !!!', { ...JSON.parse(JSON.stringify(pushSubscription)), userId: userId.value })
return $fetch('/api/subscriptions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: { ...JSON.parse(JSON.stringify(pushSubscription)), userId: _userId.value },
body: { ...JSON.parse(JSON.stringify(pushSubscription)), userId: userId.value },
})
})
.then(() => {
Expand Down Expand Up @@ -176,7 +176,7 @@ function askForNotificationPermission() {
}

const displayButton = computed(() => {
return !Notification || (Notification.permission !== 'granted' && _userId.value)
return !Notification || (Notification.permission !== 'granted' && userId.value)
})

useEventListener('scroll', async (evt) => {

Check warning on line 182 in server/nuxt3/pages/index.vue

View workflow job for this annotation

GitHub Actions / Lint

'evt' is defined but never used. Allowed unused args must match /^_/u
Expand All @@ -185,7 +185,7 @@ useEventListener('scroll', async (evt) => {
})

onMounted(async () => {
if (_userId.value)
if (userId.value)
await getDataList()
})
</script>
Expand All @@ -202,6 +202,13 @@ onMounted(async () => {
Enable Notifications
</button>
</div>
<div v-if="!userId">
<NuxtLink to="/settings">
<button btn>
Settings
</button>
</NuxtLink>
</div>
<div ref="list" flex flex-col items-center justify-center>
<div my-4 flex flex-wrap justify-center gap-4 rounded lt-sm:flex-col class="lt-sm:w-4/5">
<div v-for="item in dataList" :key="item.url">
Expand Down

1 comment on commit 5b452ec

@vercel
Copy link

@vercel vercel bot commented on 5b452ec Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

star-nexus – ./

star-nexus-git-main-larchliu.vercel.app
star-nexus-larchliu.vercel.app
star-nexus.vercel.app

Please sign in to comment.