Skip to content

Commit

Permalink
feat: ✨ Add home timeline for logged-in users
Browse files Browse the repository at this point in the history
  • Loading branch information
CPlusPatch committed Apr 29, 2024
1 parent 63cbe6b commit 8c68957
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
8 changes: 7 additions & 1 deletion components/sidebars/navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<h3 class="font-semibold text-gray-300 text-xs uppercase opacity-0 group-hover:opacity-100 duration-200">
Timelines</h3>
<NuxtLink v-for="timeline in timelines" :key="timeline.href" :to="timeline.href">
<ButtonsBase
<ButtonsBase v-if="!timeline.requiresAuth || (timeline.requiresAuth && tokenData)"
class="flex flex-row text-left items-center justify-start gap-3 text-lg hover:ring-1 ring-white/10 overflow-hidden h-12 w-full duration-200">
<Icon :name="timeline.icon" class="shrink-0 text-2xl" />
<span class="pr-28 line-clamp-1">{{ timeline.name }}</span>
Expand Down Expand Up @@ -54,6 +54,12 @@

<script lang="ts" setup>
const timelines = ref([
{
href: "/home",
name: "Home",
icon: "tabler:home",
requiresAuth: true,
},
{
href: "/public",
name: "Public",
Expand Down
17 changes: 17 additions & 0 deletions components/timelines/Home.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<TimelinesTimeline :timeline="timeline" :load-next="loadNext" :load-prev="loadPrev" />
</template>

<script lang="ts" setup>
const tokenData = useTokenData();
const client = useMegalodon(tokenData);
const timelineParameters = ref({});
const { timeline, loadNext, loadPrev } = useHomeTimeline(
client.value,
timelineParameters,
);
useListen("note:delete", ({ id }) => {
timeline.value = timeline.value.filter((note) => note.id !== id);
});
</script>
23 changes: 23 additions & 0 deletions composables/HomeTimeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Mastodon } from "megalodon";
import type { Status } from "~/types/mastodon/status";

export const useHomeTimeline = (
client: Mastodon | null,
options: MaybeRef<{
local?: boolean;
limit?: number;
max_id?: string;
since_id?: string;
min_id?: string;
}>,
): {
timeline: Ref<Status[]>;
loadNext: () => Promise<void>;
loadPrev: () => Promise<void>;
} => {
return useTimeline(
client,
(client, options) => client?.getHomeTimeline(options),
options,
);
};
9 changes: 9 additions & 0 deletions pages/home.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<TimelinesHome />
</template>

<script setup lang="ts">
definePageMeta({
layout: "app",
});
</script>

0 comments on commit 8c68957

Please sign in to comment.