Home: ignore paging for trending panel
This commit is contained in:
		
							parent
							
								
									1e84cceaf8
								
							
						
					
					
						commit
						44fbd507ac
					
				
					 2 changed files with 61 additions and 20 deletions
				
			
		| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
import { type mastodon } from "masto";
 | 
			
		||||
import { Accessor, createEffect, createResource, createSignal } from "solid-js";
 | 
			
		||||
import { Accessor, createEffect, createResource } from "solid-js";
 | 
			
		||||
import { createStore } from "solid-js/store";
 | 
			
		||||
 | 
			
		||||
type TimelineFetchTips = {
 | 
			
		||||
| 
						 | 
				
			
			@ -8,19 +8,27 @@ type TimelineFetchTips = {
 | 
			
		|||
 | 
			
		||||
type Timeline = {
 | 
			
		||||
  list(params: {
 | 
			
		||||
    maxId?: string;
 | 
			
		||||
    minId?: string;
 | 
			
		||||
    readonly limit?: number;
 | 
			
		||||
  }): mastodon.Paginator<mastodon.v1.Status[], unknown>;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export function useTimeline(timeline: Accessor<Timeline>) {
 | 
			
		||||
export function useTimeline(
 | 
			
		||||
  timeline: Accessor<Timeline>,
 | 
			
		||||
  cfg?: {
 | 
			
		||||
    /**
 | 
			
		||||
     * Use full refresh mode. This mode ignores paging, it will refetch the specified number
 | 
			
		||||
     * of toots at every refetch().
 | 
			
		||||
     */
 | 
			
		||||
    fullRefresh?: number;
 | 
			
		||||
  },
 | 
			
		||||
) {
 | 
			
		||||
  let otl: Timeline | undefined;
 | 
			
		||||
  let npager: mastodon.Paginator<mastodon.v1.Status[], unknown> | undefined;
 | 
			
		||||
  let opager: mastodon.Paginator<mastodon.v1.Status[], unknown> | undefined;
 | 
			
		||||
  const [snapshot, { refetch }] = createResource<
 | 
			
		||||
    {
 | 
			
		||||
      records: mastodon.v1.Status[];
 | 
			
		||||
      direction: "new" | "old";
 | 
			
		||||
      direction: "new" | "old" | "items";
 | 
			
		||||
      tlChanged: boolean;
 | 
			
		||||
    },
 | 
			
		||||
    [Timeline],
 | 
			
		||||
| 
						 | 
				
			
			@ -35,6 +43,20 @@ export function useTimeline(timeline: Accessor<Timeline>) {
 | 
			
		|||
        otl = tl;
 | 
			
		||||
        tlChanged = true;
 | 
			
		||||
      }
 | 
			
		||||
      const fullRefresh = cfg?.fullRefresh;
 | 
			
		||||
      if (typeof fullRefresh !== "undefined") {
 | 
			
		||||
        const records = await tl
 | 
			
		||||
          .list({
 | 
			
		||||
            limit: fullRefresh,
 | 
			
		||||
          })
 | 
			
		||||
          .next();
 | 
			
		||||
        return {
 | 
			
		||||
          direction: "items",
 | 
			
		||||
          records: records.value ?? [],
 | 
			
		||||
          end: records.done,
 | 
			
		||||
          tlChanged,
 | 
			
		||||
        };
 | 
			
		||||
      }
 | 
			
		||||
      const direction =
 | 
			
		||||
        typeof info.refetching !== "boolean"
 | 
			
		||||
          ? (info.refetching?.direction ?? "old")
 | 
			
		||||
| 
						 | 
				
			
			@ -70,10 +92,12 @@ export function useTimeline(timeline: Accessor<Timeline>) {
 | 
			
		|||
    if (tlChanged) {
 | 
			
		||||
      setStore(() => []);
 | 
			
		||||
    }
 | 
			
		||||
    if (direction == "new") {
 | 
			
		||||
    if (direction === "new") {
 | 
			
		||||
      setStore((x) => [...records, ...x]);
 | 
			
		||||
    } else if (direction == "old") {
 | 
			
		||||
    } else if (direction === "old") {
 | 
			
		||||
      setStore((x) => [...x, ...records]);
 | 
			
		||||
    } else if (direction === "items") {
 | 
			
		||||
      setStore(() => records);
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue