Skip to content

Commit

Permalink
fix for appview v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
spuithori committed Feb 1, 2024
1 parent 1cf1472 commit 7b17777
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 43 deletions.
17 changes: 10 additions & 7 deletions src/lib/components/thread/LikesModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
}
async function handleLoadMore({ detail: { loaded, complete } }) {
const res = await $agent.agent.api.app.bsky.feed.getLikes({uri: uri, cursor: cursor});
cursor = res.data.cursor;
if (cursor) {
try {
const res = await $agent.agent.api.app.bsky.feed.getLikes({uri: uri, cursor: cursor});
cursor = res.data.cursor;
likes = [...likes, ...res.data.likes];
loaded();
} else {
if (cursor) {
loaded();
} else {
complete();
}
} catch (e) {
console.error(e);
complete();
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/lib/components/thread/RepostsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
}
async function handleLoadMore({ detail: { loaded, complete } }) {
const res = await $agent.agent.api.app.bsky.feed.getRepostedBy({uri: uri, cursor: cursor});
cursor = res.data.cursor;
console.log(cursor)
if (cursor) {
try {
const res = await $agent.agent.api.app.bsky.feed.getRepostedBy({uri: uri, cursor: cursor});
cursor = res.data.cursor;
reposts = [...reposts, ...res.data.repostedBy];
loaded();
} else {
if (cursor) {
loaded();
} else {
complete();
}
} catch (e) {
console.error(e);
complete();
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {accountsDb} from "$lib/db";
import {agent, didHint} from "$lib/stores";

export function getAccountIdByDid(agents, did) {
let id;
Expand Down Expand Up @@ -63,4 +64,13 @@ export function detectDifferentDomainUrl(url: string, text: string) {
export function isFeedByUri(uri: string) {
const type = uri.split('/')[3];
return type === 'app.bsky.feed.generator';
}

export async function getDidByHandle(handle, _agent) {
if (isDid(handle)) {
return handle;
}

const res = await _agent.agent.api.com.atproto.identity.resolveHandle({ handle: handle });
return res.data.did;
}
3 changes: 1 addition & 2 deletions src/routes/(app)/profile/[handle]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ const handleLoadMore = async ({ detail: { loaded, complete } }) => {
try {
const raw = await $agent.agent.api.app.bsky.feed.getAuthorFeed({actor: data.params.handle, limit: 30, cursor: cursor});
cursor = raw.data.cursor;
feeds = [...feeds, ...raw.data.feed];
if (cursor) {
feeds = [...feeds, ...raw.data.feed];
loaded();
} else {
complete();
Expand Down
16 changes: 10 additions & 6 deletions src/routes/(app)/profile/[handle]/feed/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@
}
async function handleLoadMore({ detail: { loaded, complete } }) {
let raw = await $agent.agent.api.app.bsky.feed.getActorFeeds({actor: data.params.handle, limit: 20, cursor: cursor});
cursor = raw.data.cursor;
if (cursor) {
try {
let raw = await $agent.agent.api.app.bsky.feed.getActorFeeds({actor: data.params.handle, limit: 20, cursor: cursor});
cursor = raw.data.cursor;
feeds = [...feeds, ...raw.data.feeds];
loaded();
} else {
if (cursor) {
loaded();
} else {
complete();
}
} catch (e) {
console.error(e);
complete();
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/routes/(app)/profile/[handle]/likes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@
}
const handleLoadMore = async ({ detail: { loaded, complete } }) => {
const likesArrayRes = await getRecords();
cursor = likesArrayRes.data.cursor;
if (cursor) {
try {
const likesArrayRes = await getRecords();
cursor = likesArrayRes.data.cursor;
feeds = [...feeds, ...await getFeedsFromRecords(likesArrayRes.data.records)];
loaded();
} else {
if (cursor) {
loaded();
} else {
complete();
}
} catch (e) {
console.error(e);
complete();
}
}
Expand Down
20 changes: 13 additions & 7 deletions src/routes/(app)/profile/[handle]/lists/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@
import {agent} from "$lib/stores";
import InfiniteLoading from 'svelte-infinite-loading';
import OfficialListItem from "$lib/components/list/OfficialListItem.svelte";
import {getDidByHandle} from "$lib/util";
let lists = [];
let cursor: string | undefined = '';
export let data: LayoutData;
async function handleLoadMore({ detail: { loaded, complete } }) {
let raw = await $agent.agent.api.app.bsky.graph.getLists({actor: data.params.handle, limit: 20, cursor: cursor});
cursor = raw.data.cursor;
if (cursor) {
try {
let raw = await $agent.agent.api.app.bsky.graph.getLists({actor: await getDidByHandle(data.params.handle, $agent), limit: 20, cursor: cursor});
cursor = raw.data.cursor;
lists = [...lists, ...raw.data.lists];
loaded();
} else {
console.log(lists);
if (cursor) {
loaded();
} else {
complete();
}
} catch (e) {
console.error(e);
complete();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
cursor = res.data.cursor;
if (cursor) {
timeline = [...timeline, ...res.data.feed]
timeline = [...timeline, ...res.data.feed];
loaded();
} else {
Expand Down
13 changes: 6 additions & 7 deletions src/routes/(app)/profile/[handle]/media/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
try {
const res = await $agent.agent.api.app.bsky.feed.getAuthorFeed({actor: data.params.handle, limit: 30, cursor: cursor, filter: 'posts_with_media'});
cursor = res.data.cursor;
if (cursor) {
for (const item of res.data.feed) {
if (item.post.embed && AppBskyEmbedImages.isView(item.post.embed)) {
feeds.push(item);
}
for (const item of res.data.feed) {
if (item.post.embed && AppBskyEmbedImages.isView(item.post.embed)) {
feeds.push(item);
}
feeds = feeds;
}
feeds = feeds;
if (cursor) {
loaded();
} else {
complete();
Expand Down

0 comments on commit 7b17777

Please sign in to comment.