Skip to content

Commit

Permalink
Keep 1st id (#2038)
Browse files Browse the repository at this point in the history
Add keep id
  • Loading branch information
harsh-mn-yral authored Dec 5, 2023
1 parent df81365 commit f3e4ecf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/experiments/src/lib/db/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import type { IDBStores } from '$lib/idb/idb'
import { get } from 'svelte/store'
import { authState } from '$stores/auth'

export async function getVideos(lastRef?: QueryDocumentSnapshot) {
export async function getVideos(
lastRef?: QueryDocumentSnapshot,
keepId?: string,
) {
try {
const videos: UpDownPost[] = []
const db = getDb()
Expand Down Expand Up @@ -51,7 +54,7 @@ export async function getVideos(lastRef?: QueryDocumentSnapshot) {
)

snapshot.forEach((doc) => {
if (!alreadyWatchedPosts.includes(doc.id)) {
if (!alreadyWatchedPosts.includes(doc.id) || doc.id === keepId) {
videos.push({ ...doc.data(), id: doc.id } as UpDownPost)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { QueryDocumentSnapshot } from 'firebase/firestore'
import PlayerRenderer from '$components/layout/PlayerRenderer.svelte'
import { debounce } from 'throttle-debounce'
import { removeSplashScreen } from '$stores/popups'
import { page } from '$app/stores'
const fetchWhenVideosLeft = 5
const keepVideosLoadedCount: number = 4
Expand All @@ -24,6 +25,7 @@ let videos: UpDownPost[] = []
let currentVideoIndex = 0
let noMoreVideos = false
let loading = false
let first = true
let lastLoadedVideoRef: QueryDocumentSnapshot | undefined = undefined
let showError = false
Expand All @@ -43,7 +45,10 @@ async function fetchNextVideos() {
loading = true
const res = await getVideos(lastLoadedVideoRef)
const res = await getVideos(
lastLoadedVideoRef,
first ? $page.params.id : undefined,
)
if (!res.ok || !res.videos) {
console.log('r2')
return
Expand Down

0 comments on commit f3e4ecf

Please sign in to comment.