forked from jsnbuchanan/crowd-funder-for-time-pwa
feat: add starred project list in search, refactor variable names
This commit is contained in:
@@ -56,16 +56,26 @@
|
||||
href="#"
|
||||
:class="computedStarredTabStyleClassNames()"
|
||||
@click="
|
||||
projects = [];
|
||||
userProfiles = [];
|
||||
isStarredActive = true;
|
||||
isLocalActive = false;
|
||||
isMappedActive = false;
|
||||
isAnywhereActive = false;
|
||||
isStarredActive = true;
|
||||
isSearchVisible = false;
|
||||
tempSearchBox = null;
|
||||
loadStarred();
|
||||
searchStarred();
|
||||
"
|
||||
>
|
||||
Starred
|
||||
<!-- restore when the links don't jump around for different numbers
|
||||
<span
|
||||
class="font-semibold text-sm bg-slate-200 px-1.5 py-0.5 rounded-md"
|
||||
v-if="isLocalActive"
|
||||
>
|
||||
{{ localCount > -1 ? localCount : "?" }}
|
||||
</span>
|
||||
-->
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
@@ -75,6 +85,7 @@
|
||||
@click="
|
||||
projects = [];
|
||||
userProfiles = [];
|
||||
isStarredActive = false;
|
||||
isLocalActive = true;
|
||||
isMappedActive = false;
|
||||
isAnywhereActive = false;
|
||||
@@ -102,6 +113,7 @@
|
||||
@click="
|
||||
projects = [];
|
||||
userProfiles = [];
|
||||
isStarredActive = false;
|
||||
isLocalActive = false;
|
||||
isMappedActive = true;
|
||||
isAnywhereActive = false;
|
||||
@@ -122,6 +134,7 @@
|
||||
@click="
|
||||
projects = [];
|
||||
userProfiles = [];
|
||||
isStarredActive = false;
|
||||
isLocalActive = false;
|
||||
isMappedActive = false;
|
||||
isAnywhereActive = true;
|
||||
@@ -222,7 +235,9 @@
|
||||
that search.</span
|
||||
>
|
||||
<span v-else-if="isStarredActive">
|
||||
<p>You have no starred projects. Star some projects to see them here.</p>
|
||||
<p>
|
||||
You have no starred projects. Star some projects to see them here.
|
||||
</p>
|
||||
<p class="mt-4">
|
||||
When you star projects, you will get a notice on the front page when
|
||||
they change.
|
||||
@@ -360,10 +375,8 @@ import {
|
||||
didInfo,
|
||||
errorStringForLog,
|
||||
getHeaders,
|
||||
getPlanFromCache,
|
||||
} from "../libs/endorserServer";
|
||||
import { OnboardPage, retrieveAccountDids } from "../libs/util";
|
||||
import { parseJsonField } from "../db/databaseUtil";
|
||||
import { logger } from "../utils/logger";
|
||||
import { UserProfile } from "@/libs/partnerServer";
|
||||
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
|
||||
@@ -416,10 +429,12 @@ export default class DiscoverView extends Vue {
|
||||
allMyDids: Array<string> = [];
|
||||
apiServer = "";
|
||||
isLoading = false;
|
||||
|
||||
isLocalActive = false;
|
||||
isMappedActive = false;
|
||||
isAnywhereActive = true;
|
||||
isStarredActive = false;
|
||||
|
||||
isProjectsActive = true;
|
||||
isPeopleActive = false;
|
||||
isSearchVisible = true;
|
||||
@@ -505,7 +520,7 @@ export default class DiscoverView extends Vue {
|
||||
};
|
||||
this.requestTiles(mapRef.leafletObject); // not ideal because I found this from experimentation, not documentation
|
||||
} else if (this.isStarredActive) {
|
||||
await this.loadStarred();
|
||||
await this.searchStarred();
|
||||
} else {
|
||||
await this.searchAll();
|
||||
}
|
||||
@@ -576,7 +591,7 @@ export default class DiscoverView extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
public async loadStarred() {
|
||||
public async searchStarred() {
|
||||
this.resetCounts();
|
||||
|
||||
// Clear any previous results
|
||||
@@ -588,52 +603,37 @@ export default class DiscoverView extends Vue {
|
||||
|
||||
// Get starred project IDs from settings
|
||||
const settings = await this.$accountSettings();
|
||||
const starredIds: string[] = parseJsonField(
|
||||
settings.starredProjectIds,
|
||||
[],
|
||||
);
|
||||
|
||||
const starredIds = settings.starredPlanHandleIds || [];
|
||||
if (starredIds.length === 0) {
|
||||
// No starred projects
|
||||
return;
|
||||
}
|
||||
|
||||
// Load each starred project using getPlanFromCache
|
||||
const projectPromises = starredIds.map(async (handleId) => {
|
||||
try {
|
||||
const project = await getPlanFromCache(
|
||||
handleId,
|
||||
this.axios,
|
||||
this.apiServer,
|
||||
this.activeDid,
|
||||
);
|
||||
if (project) {
|
||||
// Convert PlanSummaryRecord to PlanData
|
||||
return {
|
||||
description: project.description,
|
||||
handleId: project.handleId,
|
||||
image: project.image,
|
||||
issuerDid: project.issuerDid,
|
||||
name: project.name || UNNAMED_PROJECT,
|
||||
rowId: project.jwtId,
|
||||
} as PlanData;
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
logger.warn(`Failed to load starred project ${handleId}:`, error);
|
||||
return null;
|
||||
}
|
||||
// This could be optimized to only pull those not already in the cache (endorserServer.ts)
|
||||
|
||||
const planHandleIdsJson = JSON.stringify(starredIds);
|
||||
const endpoint =
|
||||
this.apiServer +
|
||||
"/api/v2/report/plans?planHandleIds=" +
|
||||
encodeURIComponent(planHandleIdsJson);
|
||||
const response = await this.axios.get(endpoint, {
|
||||
headers: await getHeaders(this.activeDid),
|
||||
});
|
||||
if (response.status !== 200) {
|
||||
this.notify.error("Failed to load starred projects", TIMEOUTS.SHORT);
|
||||
return;
|
||||
}
|
||||
const starredPlans: PlanData[] = response.data.data;
|
||||
if (response.data.hitLimit) {
|
||||
// someday we'll have to let them incrementally load the rest
|
||||
this.notify.warning(
|
||||
"Beware: you have so many starred projects that we cannot load them all.",
|
||||
TIMEOUTS.SHORT,
|
||||
);
|
||||
}
|
||||
|
||||
const projects = await Promise.all(projectPromises);
|
||||
|
||||
// Filter out null results and add to projects array
|
||||
const validProjects = projects.filter(
|
||||
(project): project is PlanData =>
|
||||
project !== null && project !== undefined,
|
||||
);
|
||||
|
||||
this.projects = validProjects;
|
||||
this.projects = starredPlans;
|
||||
} catch (error: unknown) {
|
||||
logger.error("Error loading starred projects:", error);
|
||||
this.notify.error(
|
||||
@@ -738,6 +738,8 @@ export default class DiscoverView extends Vue {
|
||||
const latestProject = this.projects[this.projects.length - 1];
|
||||
if (this.isLocalActive || this.isMappedActive) {
|
||||
this.searchLocal(latestProject.rowId);
|
||||
} else if (this.isStarredActive) {
|
||||
this.searchStarred();
|
||||
} else if (this.isAnywhereActive) {
|
||||
this.searchAll(latestProject.rowId);
|
||||
}
|
||||
@@ -881,6 +883,24 @@ export default class DiscoverView extends Vue {
|
||||
this.$router.push(route);
|
||||
}
|
||||
|
||||
public computedStarredTabStyleClassNames() {
|
||||
return {
|
||||
"inline-block": true,
|
||||
"py-3": true,
|
||||
"rounded-t-lg": true,
|
||||
"border-b-2": true,
|
||||
|
||||
active: this.isStarredActive,
|
||||
"text-black": this.isStarredActive,
|
||||
"border-black": this.isStarredActive,
|
||||
"font-semibold": this.isStarredActive,
|
||||
|
||||
"text-blue-600": !this.isStarredActive,
|
||||
"border-transparent": !this.isStarredActive,
|
||||
"hover:border-slate-400": !this.isStarredActive,
|
||||
};
|
||||
}
|
||||
|
||||
public computedLocalTabStyleClassNames() {
|
||||
return {
|
||||
"inline-block": true,
|
||||
@@ -935,24 +955,6 @@ export default class DiscoverView extends Vue {
|
||||
};
|
||||
}
|
||||
|
||||
public computedStarredTabStyleClassNames() {
|
||||
return {
|
||||
"inline-block": true,
|
||||
"py-3": true,
|
||||
"rounded-t-lg": true,
|
||||
"border-b-2": true,
|
||||
|
||||
active: this.isStarredActive,
|
||||
"text-black": this.isStarredActive,
|
||||
"border-black": this.isStarredActive,
|
||||
"font-semibold": this.isStarredActive,
|
||||
|
||||
"text-blue-600": !this.isStarredActive,
|
||||
"border-transparent": !this.isStarredActive,
|
||||
"hover:border-slate-400": !this.isStarredActive,
|
||||
};
|
||||
}
|
||||
|
||||
public computedProjectsTabStyleClassNames() {
|
||||
return {
|
||||
"inline-block": true,
|
||||
|
||||
Reference in New Issue
Block a user