Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explorer fetch function refactored #2704

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 42 additions & 60 deletions src/pages/Explorer/Category/ExplorerCategory.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,45 +79,49 @@
items = items
})

function fetch(bypassLoading = false) {
async function setInsightItems() {
if (activeMenu !== MenuItem.TRENDING) return
const insightItems = await queryExplorerItems({
types: [EntityKeys.INSIGHT],
page: insightsPage,
})
insightsPages = insightItems.pages
insights = insightsPage === 1 ? insightItems.items : insights.concat(insightItems.items)
}

async function setDisplayingItems() {
const displayingItems = await queryExplorerItems({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @Woafflation described, separate insights' query was added as hotfix to support insights in the feed. Now it is not required, since it's natively supported by the api.

queryExplorerItems({
types: [EntityKeys.INSIGHT],
page: insightsPage,
})
.then((res) => {
if (activeMenu === MenuItem.TRENDING) {
insightsPages = res.pages
insights = insightsPage === 1 ? res.items : insights.concat(res.items)
}
})
.catch(() => notifyError({ user: $currentUser }))
.finally(() => {
queryExplorerItems({
types: getDisplayingType(displayingTypes),

The inisght specific query function can be removed (LOC 82)

peratik marked this conversation as resolved.
Show resolved Hide resolved
types: getDisplayingType(displayingTypes),
voted,
favorites,
range,
page,
currentUserDataOnly,
assets,
userRoleDataOnly,
isFeaturedDataOnly,
})
pages = displayingItems.pages
items = page === 1 ? displayingItems.items : items.concat(displayingItems.items)
}

async function fetch(bypassLoading = false) {
if (showEmpty) {
pages = 1
page = 1
items = []
return
}
if (!bypassLoading) loading = true

queryExplorerItems({
types: [EntityKeys.INSIGHT],
page: insightsPage,
})
.then((res) => {
if (activeMenu === MenuItem.TRENDING) {
insightsPages = res.pages
insights = insightsPage === 1 ? res.items : insights.concat(res.items)
}
})
.catch(() => notifyError({ user: $currentUser }))
.finally(() => {
queryExplorerItems({
types: getDisplayingType(displayingTypes),
voted,
favorites,
range,
page,
currentUserDataOnly,
assets,
userRoleDataOnly,
isFeaturedDataOnly,
})
.then((res) => {
pages = res.pages
items = page === 1 ? res.items : items.concat(res.items)
})
.catch(() => notifyError({ user: $currentUser }))
.finally(() => (loading = false))
})
try {
loading = !bypassLoading
await setInsightItems()
await setDisplayingItems()
} catch {
notifyError({ user: $currentUser })
} finally {
loading = false
}
}

function reset() {
Expand Down Expand Up @@ -157,26 +161,9 @@
}

onMount(() => {
if (activeMenu === MenuItem.TRENDING) {
queryExplorerItems({
types: getDisplayingType(displayingTypes),
voted,
favorites,
range,
page,
currentUserDataOnly,
assets,
userRoleDataOnly,
isFeaturedDataOnly,
})
.then((res) => {
if (res.items.length === 0) activeMenu = MenuItem.NEW
})
.catch(() => notifyError({ user: $currentUser }))
}

pullingTimer = setTimeout(() => fetch(true), 60 * 1000)
})

onDestroy(() => clearTimeout(pullingTimer))
</script>

Expand All @@ -193,8 +180,7 @@
insightsPage += 1
trackExplorerShowMore({ page, size: 20 })
}}
hasMore={page < pages}
>
hasMore={page < pages}>
<div slot="header" class="controls row mrg-a mrg--l">
<TypeSelector
flat
Expand All @@ -203,8 +189,7 @@
page = 1
insightsPage = 1
}}
{displayingTypes}
/>
{displayingTypes} />
</div>

<svelte:fragment let:item>
Expand All @@ -214,24 +199,21 @@
showActions
type="CHART"
hasIcons
assets={getAssets(item.chartConfiguration)}
/>
assets={getAssets(item.chartConfiguration)} />
{:else if item.screener}
<LayoutItem
item={item.screener}
showActions
type="SCREENER"
id="{item.screener.id}-watchlist"
/>
id="{item.screener.id}-watchlist" />
{:else if item.projectWatchlist}
<LayoutItem item={item.projectWatchlist} showActions type="WATCHLIST" />
{:else if item.addressWatchlist}
<LayoutItem
item={item.addressWatchlist}
showActions
type="ADDRESS"
assets={getAddressLabels(item.addressWatchlist.listItems)}
/>
assets={getAddressLabels(item.addressWatchlist.listItems)} />
{:else if item.insight}
<LayoutItem item={item.insight} showActions type="INSIGHT" />
{:else if item.userTrigger}
Expand Down