diff --git a/package-lock.json b/package-lock.json index 16e600561..ca5583bb2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18633,7 +18633,7 @@ "lodash.clonedeep": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", - "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==" + "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=" }, "lodash.debounce": { "version": "4.0.8", @@ -18649,7 +18649,7 @@ "lodash.escaperegexp": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz", - "integrity": "sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw==" + "integrity": "sha1-ZHYsSGGAglGKw99Mz11YhtriA0c=" }, "lodash.every": { "version": "4.6.0", @@ -30521,7 +30521,7 @@ "srcset": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/srcset/-/srcset-1.0.0.tgz", - "integrity": "sha512-UH8e80l36aWnhACzjdtLspd4TAWldXJMa45NuOkTTU+stwekswObdqM63TtQixN4PPd/vO/kxLa6RD+tUPeFMg==", + "integrity": "sha1-pWad4StC87HV6D7QPHEEb8SPQe8=", "requires": { "array-uniq": "^1.0.2", "number-is-nan": "^1.0.0" diff --git a/src/pages/Explorer/Category/Category.svelte b/src/pages/Explorer/Category/Category.svelte index 6ffbb0ab3..ff9def03c 100644 --- a/src/pages/Explorer/Category/Category.svelte +++ b/src/pages/Explorer/Category/Category.svelte @@ -6,7 +6,6 @@ export { className as class } export let title export let items = [] - export let insights = [] export let hasMore = true export let onMore export let small = false @@ -15,11 +14,9 @@ export let showLess = false export let isMain = false export let favorites = false - export let hasInsights = false export let sortedItems = [] $: isMain && changeOrder(items) - $: isMain && changeOrder(insights) // Formula: Likes * 0.3 + Comments * 0.7 const getRank = (item) => item.votes.totalVotes * 0.3 + item.commentsCount * 0.7 @@ -88,7 +85,7 @@ {/if} - {#each isMain ? sortedItems : items as item, index (item)} + {#each isMain ? sortedItems : items as item (item)} {#if isMain && item.first && !favorites}
{item.postdate}
{/if} @@ -102,24 +99,8 @@ > - {@const itemCount = index + 1} - {@const insight = insights[itemCount / 2]} - {#if hasInsights && favorites && itemCount % 2 === 0 && insight} -
- -
- {/if} {/each} - {#if hasInsights && insights.length > 0 && !loading && !hasMore && favorites && isMain} - {@const restInsights = insights.slice(items.length / 2)} - {#each restInsights as insight} -
- -
- {/each} - {/if} - {#if hasMore || showLess}
{} let loading = false let deletedItems = [] - let hasInsights = false $: activeMenu, reset() $: showEmpty = !$currentUser && [MenuItem.MY_CREATIONS, MenuItem.LIKES].includes(activeMenu) @@ -39,7 +35,6 @@ $: userRoleDataOnly = activeMenu === MenuItem.SANTIMENT $: isFeaturedDataOnly = [MenuItem.TRENDING, MenuItem.SANTIMENT].includes(activeMenu) $: range, assets, displayingTypes, page, fetch() - $: displayingTypes, filterInsights() $: onLoadingChange(loading) $: items = filterDeletedItems(deletedItems) @@ -79,50 +74,42 @@ items = items }) - function fetch(bypassLoading = false) { + async function setDisplayingItems() { + const data = await queryExplorerItems({ + types: getDisplayingType(displayingTypes), + voted, + favorites, + range, + page, + currentUserDataOnly, + assets, + userRoleDataOnly, + isFeaturedDataOnly, + }) + pages = data.pages + items = page === 1 ? data.items : items.concat(data.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 setDisplayingItems() + } catch { + notifyError({ user: $currentUser }) + } finally { + loading = false + } } function reset() { page = 1 - insightsPage = 1 deselectAssets() displayingTypes = new Set() range = '' @@ -145,38 +132,10 @@ return labels } - function filterInsights() { - const values = new Set(getDisplayingType(displayingTypes)) - hasInsights = values.has(EntityKeys.INSIGHT) - - if (!hasInsights) { - insights = [] - insightsPage = 1 - insightsPages = 1 - } - } - 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)) @@ -185,26 +144,20 @@ {favorites} title="Explorer" {items} - {insights} - {hasInsights} {loading} onMore={() => { page += 1 - insightsPage += 1 trackExplorerShowMore({ page, size: 20 }) }} - hasMore={page < pages} -> + hasMore={page < pages}>
{ displayingTypes = newTypes page = 1 - insightsPage = 1 }} - {displayingTypes} - /> + {displayingTypes} />
@@ -214,15 +167,13 @@ showActions type="CHART" hasIcons - assets={getAssets(item.chartConfiguration)} - /> + assets={getAssets(item.chartConfiguration)} /> {:else if item.screener} + id="{item.screener.id}-watchlist" /> {:else if item.projectWatchlist} {:else if item.addressWatchlist} @@ -230,8 +181,7 @@ item={item.addressWatchlist} showActions type="ADDRESS" - assets={getAddressLabels(item.addressWatchlist.listItems)} - /> + assets={getAddressLabels(item.addressWatchlist.listItems)} /> {:else if item.insight} {:else if item.userTrigger} @@ -240,6 +190,6 @@ -{#if showEmpty || (!loading && items.length === 0 && insights.length === 0)} +{#if showEmpty || (!loading && items.length === 0)} {/if}