From 70cffc3b556b854091da579524fd33816e8a5b52 Mon Sep 17 00:00:00 2001 From: SaeidR Date: Wed, 18 Jan 2023 01:33:13 -0500 Subject: [PATCH 1/5] explorer fetch function refactored --- package-lock.json | 6 +- .../Explorer/Category/ExplorerCategory.svelte | 83 +++++++++---------- 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/package-lock.json b/package-lock.json index 16e6005614..ca5583bb22 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/ExplorerCategory.svelte b/src/pages/Explorer/Category/ExplorerCategory.svelte index a315dbdfc4..e16eac65b9 100644 --- a/src/pages/Explorer/Category/ExplorerCategory.svelte +++ b/src/pages/Explorer/Category/ExplorerCategory.svelte @@ -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({ + 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() { @@ -193,8 +197,7 @@ insightsPage += 1 trackExplorerShowMore({ page, size: 20 }) }} - hasMore={page < pages} -> + hasMore={page < pages}>
+ {displayingTypes} />
@@ -214,15 +216,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 +230,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} From 2d698e6eefd1f5acb25364b2cbda4714bc57b494 Mon Sep 17 00:00:00 2001 From: SaeidR Date: Wed, 18 Jan 2023 02:45:19 -0500 Subject: [PATCH 2/5] unused block removed --- .../Explorer/Category/ExplorerCategory.svelte | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/pages/Explorer/Category/ExplorerCategory.svelte b/src/pages/Explorer/Category/ExplorerCategory.svelte index e16eac65b9..a93e58c35d 100644 --- a/src/pages/Explorer/Category/ExplorerCategory.svelte +++ b/src/pages/Explorer/Category/ExplorerCategory.svelte @@ -161,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)) From 0cb68b8a3516cd868b45f894c25ce9691fbbe4aa Mon Sep 17 00:00:00 2001 From: SaeidR Date: Wed, 18 Jan 2023 06:12:36 -0500 Subject: [PATCH 3/5] PR comments applied --- .../Explorer/Category/ExplorerCategory.svelte | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/pages/Explorer/Category/ExplorerCategory.svelte b/src/pages/Explorer/Category/ExplorerCategory.svelte index a93e58c35d..82dccf9fba 100644 --- a/src/pages/Explorer/Category/ExplorerCategory.svelte +++ b/src/pages/Explorer/Category/ExplorerCategory.svelte @@ -79,18 +79,8 @@ items = items }) - 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({ + const data = await queryExplorerItems({ types: getDisplayingType(displayingTypes), voted, favorites, @@ -101,8 +91,8 @@ userRoleDataOnly, isFeaturedDataOnly, }) - pages = displayingItems.pages - items = page === 1 ? displayingItems.items : items.concat(displayingItems.items) + pages = data.pages + items = page === 1 ? data.items : items.concat(data.items) } async function fetch(bypassLoading = false) { @@ -115,7 +105,6 @@ try { loading = !bypassLoading - await setInsightItems() await setDisplayingItems() } catch { notifyError({ user: $currentUser }) From 9043f9bd0245de7a773c97fafcf977b84a2fef08 Mon Sep 17 00:00:00 2001 From: SaeidR Date: Wed, 18 Jan 2023 06:21:30 -0500 Subject: [PATCH 4/5] insight related codes removed --- src/pages/Explorer/Category/Category.svelte | 18 --------------- .../Explorer/Category/ExplorerCategory.svelte | 23 +------------------ 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/src/pages/Explorer/Category/Category.svelte b/src/pages/Explorer/Category/Category.svelte index 6ffbb0ab3d..cfb2893727 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 @@ -103,23 +100,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) @@ -115,7 +110,6 @@ function reset() { page = 1 - insightsPage = 1 deselectAssets() displayingTypes = new Set() range = '' @@ -138,17 +132,6 @@ return labels } - function filterInsights() { - const values = new Set(getDisplayingType(displayingTypes)) - hasInsights = values.has(EntityKeys.INSIGHT) - - if (!hasInsights) { - insights = [] - insightsPage = 1 - insightsPages = 1 - } - } - onMount(() => { pullingTimer = setTimeout(() => fetch(true), 60 * 1000) }) @@ -161,12 +144,9 @@ {favorites} title="Explorer" {items} - {insights} - {hasInsights} {loading} onMore={() => { page += 1 - insightsPage += 1 trackExplorerShowMore({ page, size: 20 }) }} hasMore={page < pages}> @@ -176,7 +156,6 @@ onChange={(newTypes) => { displayingTypes = newTypes page = 1 - insightsPage = 1 }} {displayingTypes} />
@@ -211,6 +190,6 @@
-{#if showEmpty || (!loading && items.length === 0 && insights.length === 0)} +{#if showEmpty || (!loading && items.length === 0)} {/if} From aeeaf289da7490a251cd8def21bf5dd2a96e96ad Mon Sep 17 00:00:00 2001 From: SaeidR Date: Wed, 18 Jan 2023 06:23:21 -0500 Subject: [PATCH 5/5] unused code removed --- src/pages/Explorer/Category/Category.svelte | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/Explorer/Category/Category.svelte b/src/pages/Explorer/Category/Category.svelte index cfb2893727..ff9def03c9 100644 --- a/src/pages/Explorer/Category/Category.svelte +++ b/src/pages/Explorer/Category/Category.svelte @@ -85,7 +85,7 @@ {/if} - {#each isMain ? sortedItems : items as item, index (item)} + {#each isMain ? sortedItems : items as item (item)} {#if isMain && item.first && !favorites} {/if} @@ -99,7 +99,6 @@ > - {@const itemCount = index + 1} {/each} {#if hasMore || showLess}