Skip to content

Commit c38346d

Browse files
committed
add toasts, update UI
1 parent 4d854e2 commit c38346d

File tree

3 files changed

+48
-29
lines changed

3 files changed

+48
-29
lines changed

components/ActivityFeed.vue

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<script setup>
22
import { Inbox } from "lucide-vue-next";
33
import Knock from "@knocklabs/client";
4+
import { useToast } from "@/components/ui/toast/use-toast";
5+
const { toast } = useToast();
46
const runtimeConfig = useRuntimeConfig();
57
const knockClient = new Knock(runtimeConfig.public.knockPublicApiKey);
6-
knockClient.authenticate(runtimeConfig.public.knockUserId);
8+
knockClient.authenticate(runtimeConfig.public.knockUserId, undefined, {
9+
logLevel: "debug",
10+
});
711
const knockFeed = knockClient.feeds.initialize(
812
runtimeConfig.public.knockFeedChannelId,
913
{
@@ -15,6 +19,7 @@ const feed = ref({});
1519
await knockFeed.fetch();
1620
const feedState = knockFeed.getState();
1721
feed.value = feedState;
22+
knockFeed.listenForUpdates();
1823
1924
const feedItems = computed(() => {
2025
return feed.value.items.filter((item) => !item.archived_at);
@@ -27,7 +32,23 @@ knockFeed.on("items.received.*", ({ items }) => {
2732
});
2833
2934
knockFeed.on("items.*", () => {
30-
console.log("calling items.*");
35+
feed.value = knockFeed.getState();
36+
});
37+
knockFeed.on("items.received.realtime", ({ items }) => {
38+
items.forEach((item) => {
39+
console.log(item);
40+
if (item.data && item.data.showToast) {
41+
toast({
42+
title: `📨 New feed item at ${new Date(
43+
item.inserted_at
44+
).toLocaleString()}`,
45+
description: "Snap! This real-time feed is mind-blowing 🤯",
46+
});
47+
}
48+
});
49+
});
50+
51+
knockFeed.on("items.*", () => {
3152
feed.value = knockFeed.getState();
3253
});
3354
</script>
@@ -57,23 +78,23 @@ knockFeed.on("items.*", () => {
5778
</Dialog>
5879
</TabsList>
5980
<TabsContent value="inbox">
60-
<div class="my-6 flex">
61-
<Button
62-
variant="outline"
63-
class="w-full mr-2"
64-
@click="knockFeed.markAllAsRead()"
65-
>
66-
Mark all as read
67-
</Button>
68-
<Button
69-
variant="outline"
70-
class="w-full ml-2"
71-
@click="knockFeed.markAllAsArchived()"
72-
>
73-
Archive all
74-
</Button>
75-
</div>
7681
<div v-if="feedItems.length > 0">
82+
<div class="my-6 flex">
83+
<Button
84+
variant="outline"
85+
class="w-full mr-2"
86+
@click="knockFeed.markAllAsRead()"
87+
>
88+
Mark all as read
89+
</Button>
90+
<Button
91+
variant="outline"
92+
class="w-full ml-2"
93+
@click="knockFeed.markAllAsArchived()"
94+
>
95+
Archive all
96+
</Button>
97+
</div>
7798
<FeedItemCard
7899
v-for="item in feedItems"
79100
:key="item.id"
@@ -90,13 +111,11 @@ knockFeed.on("items.*", () => {
90111
</div>
91112

92113
<div
93-
class="flex flex-col items-center my-12 py-12 bg-slate-50 rounded-md"
94-
v-if="feed.items.length < 0"
114+
class="flex flex-col items-center content-center my-12 py-12 bg-slate-50 rounded-md"
115+
v-if="!feedItems || feedItems.length === 0"
95116
>
96-
<div>
97-
<Inbox class="w-16 h-16"></Inbox>
98-
<p class="mt-6">You&apos;re all caught up</p>
99-
</div>
117+
<Inbox class="w-16 h-16"></Inbox>
118+
<p class="mt-6">You&apos;re all caught up</p>
100119
</div>
101120
</TabsContent>
102121
<TabsContent value="archived">

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"postinstall": "nuxt prepare"
1111
},
1212
"dependencies": {
13-
"@knocklabs/client": "^0.10.5",
13+
"@knocklabs/client": "^0.10.7",
1414
"class-variance-authority": "^0.7.0",
1515
"clsx": "^2.1.1",
1616
"lucide-vue-next": "^0.378.0",

0 commit comments

Comments
 (0)