Browse Source

Beginning of integration. Seems the data coming back from local and remote are different?

similarify-search
Matthew Raymer 1 year ago
parent
commit
1d362c314b
  1. 71
      src/views/DiscoverView.vue

71
src/views/DiscoverView.vue

@ -30,7 +30,10 @@
<li> <li>
<a <a
href="#" href="#"
@click="searchLocal()" @click="
projects = [];
searchLocal();
"
v-bind:class="computedLocalTabClassNames()" v-bind:class="computedLocalTabClassNames()"
> >
Nearby Nearby
@ -44,7 +47,10 @@
<a <a
href="#" href="#"
v-bind:class="computedRemoteTabClassNames()" v-bind:class="computedRemoteTabClassNames()"
@click="search()" @click="
projects = [];
search();
"
> >
Remote Remote
<span <span
@ -65,7 +71,8 @@
</div> </div>
<!-- Results List --> <!-- Results List -->
<ul v-if="projects.length > 0"> <InfiniteScroll @reached-bottom="loadMoreData">
<ul>
<li <li
class="border-b border-slate-300" class="border-b border-slate-300"
v-for="project in projects" v-for="project in projects"
@ -92,7 +99,7 @@
</a> </a>
</li> </li>
</ul> </ul>
<p v-else>No projects found yet.</p> </InfiniteScroll>
<AlertMessage <AlertMessage
:alertTitle="alertTitle" :alertTitle="alertTitle"
:alertMessage="alertMessage" :alertMessage="alertMessage"
@ -108,9 +115,10 @@ import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken } from "@/libs/crypto"; import { accessToken } from "@/libs/crypto";
import AlertMessage from "@/components/AlertMessage"; import AlertMessage from "@/components/AlertMessage";
import QuickNav from "@/components/QuickNav"; import QuickNav from "@/components/QuickNav";
import InfiniteScroll from "@/components/InfiniteScroll";
@Component({ @Component({
components: { AlertMessage, QuickNav }, components: { AlertMessage, QuickNav, InfiniteScroll },
}) })
export default class DiscoverView extends Vue { export default class DiscoverView extends Vue {
activeDid = ""; activeDid = "";
@ -155,11 +163,16 @@ export default class DiscoverView extends Vue {
return headers; return headers;
} }
public async search() { public async search(beforeId?: string) {
const claimContents = const claimContents =
"claimContents=" + encodeURIComponent(this.searchTerms); "claimContents=" + encodeURIComponent(this.searchTerms);
const claimType = "claimType=PlanAction"; const claimType = "claimType=PlanAction";
const queryParams = [claimContents, claimType].join("&"); let queryParams = [claimContents, claimType].join("&");
console.log(beforeId);
if (beforeId) {
queryParams = queryParams + `beforeId=${beforeId}`;
}
this.isRemoteActive = true; this.isRemoteActive = true;
this.isLocalActive = false; this.isLocalActive = false;
@ -181,8 +194,13 @@ export default class DiscoverView extends Vue {
const results = await response.json(); const results = await response.json();
if (results.data) { const plans: ProjectData[] = results.data;
this.projects = results.data; if (plans) {
for (const plan of plans) {
const { name, description, handleId = plan.fullIri, rowid } = plan;
console.log("here");
this.projects.push({ name, description, handleId, rowid });
}
this.remoteCount = this.projects.length; this.remoteCount = this.projects.length;
} else { } else {
throw JSON.stringify(results); throw JSON.stringify(results);
@ -197,10 +215,10 @@ export default class DiscoverView extends Vue {
} }
} }
public async searchLocal() { public async searchLocal(beforeId?: string) {
const claimContents = const claimContents =
"claimContents=" + encodeURIComponent(this.searchTerms); "claimContents=" + encodeURIComponent(this.searchTerms);
const queryParams = [ let queryParams = [
claimContents, claimContents,
"minLocLat=40.901000", "minLocLat=40.901000",
"maxLocLat=40.904000", "maxLocLat=40.904000",
@ -208,6 +226,10 @@ export default class DiscoverView extends Vue {
"eastLocLon=-111.909000", "eastLocLon=-111.909000",
].join("&"); ].join("&");
if (beforeId) {
queryParams = queryParams + `beforeId=${beforeId}`;
}
try { try {
this.isLoading = true; this.isLoading = true;
this.isLocalActive = true; this.isLocalActive = true;
@ -227,7 +249,17 @@ export default class DiscoverView extends Vue {
const results = await response.json(); const results = await response.json();
if (results.data) { if (results.data) {
if (beforeId) {
const plans: ProjectData[] = results.data;
for (const plan of plans) {
const { name, description, handleId = plan.fullIri, rowid } = plan;
if (beforeId !== plan["rowid"]) {
this.projects.push({ name, description, handleId, rowid });
}
}
} else {
this.projects = results.data; this.projects = results.data;
}
this.localCount = this.projects.length; this.localCount = this.projects.length;
} else { } else {
throw JSON.stringify(results); throw JSON.stringify(results);
@ -242,6 +274,23 @@ export default class DiscoverView extends Vue {
} }
} }
/**
* Data loader used by infinite scroller
* @param payload is the flag from the InfiniteScroll indicating if it should load
**/
async loadMoreData(payload: boolean) {
if (this.projects.length > 0 && payload) {
const latestProject = this.projects[this.projects.length - 1];
console.log("rowid", latestProject, payload);
console.log(Object.keys(latestProject));
if (this.isLocalActive) {
this.searchLocal(latestProject["rowid"]);
} else if (this.isRemoteActive) {
this.search(latestProject["rowid"]);
}
}
}
/** /**
* Handle clicking on a project entry found in the list * Handle clicking on a project entry found in the list
* @param id of the project * @param id of the project

Loading…
Cancel
Save