Skip to content

Commit

Permalink
fix: scrolling lost on recipe edit and unlabeled filter (#1457)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoy authored Oct 13, 2024
2 parents 5eb17f8 + a89cc0e commit 9054b6a
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 54 deletions.
74 changes: 42 additions & 32 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@ngx-loading-bar/core": "^6.0.2",
"@ngx-translate/core": "^15.0.0",
"@ngx-translate/http-loader": "^8.0.0",
"@prisma/client": "^5.11.0",
"@prisma/client": "^5.20.0",
"@sentry/browser": "^7.109.0",
"@sentry/node": "^7.109.0",
"@sentry/tracing": "^7.109.0",
Expand Down Expand Up @@ -69,7 +69,7 @@
"pdfmake": "^0.2.10",
"pg": "8.11.4",
"pg-hstore": "^2.3.4",
"prisma": "^5.11.0",
"prisma": "^5.20.0",
"pug": "^3.0.3",
"puppeteer-core": "^22.15.0",
"sanitize-html": "^2.13.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class HomeSearchFilterPopoverPage {
this.popoverCtrl.dismiss({
refreshSearch,
ratingFilter: this.ratingFilter,
selectedLabels: this.selectedLabels,
});
}

Expand Down
30 changes: 18 additions & 12 deletions packages/frontend/src/app/pages/home/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@ export class HomePage {

if (this.reloadPending) {
const loading = this.loadingService.start();
this.resetAndLoadAll().finally(() => {
loading.dismiss();
});
this.resetAndLoadAll(this.datasource.adapter.firstVisible.$index).finally(
() => {
loading.dismiss();
},
);
}

this.fetchMyProfile();
Expand Down Expand Up @@ -225,6 +227,8 @@ export class HomePage {
if (tileColCount !== this.tileColCount) {
this.tileColCount = tileColCount;

// We set to zero since we don't know what the relative position would be now
this.datasource.settings!.startIndex = 0;
this.datasource.adapter.reset();
}
}
Expand All @@ -241,26 +245,26 @@ export class HomePage {
}
}

async resetAndLoadAll(): Promise<any> {
async resetAndLoadAll(scrollToIndex?: number): Promise<any> {
this.reloadPending = false;

// Load labels & recipes in parallel if user hasn't selected labels that need to be verified for existence
// Or if we're loading someone elses collection (in which case we can't verify)
if (this.selectedLabels.length === 0 || this.userId) {
return Promise.all([
this.resetAndLoadLabels(),
this.resetAndLoadRecipes(),
this.resetAndLoadRecipes(scrollToIndex),
]);
}

return this.resetAndLoadLabels().then(() => {
const labelNames = new Set(this.labels.map((e) => e.title));

this.selectedLabels = this.selectedLabels.filter((e) =>
labelNames.has(e),
this.selectedLabels = this.selectedLabels.filter(
(e) => labelNames.has(e) || e === "unlabeled",
);

return this.resetAndLoadRecipes();
return this.resetAndLoadRecipes(scrollToIndex);
});
}

Expand All @@ -269,11 +273,11 @@ export class HomePage {
return this.loadLabels();
}

resetAndLoadRecipes() {
resetAndLoadRecipes(scrollToIndex?: number) {
this.loading = true;
this.resetRecipes();

return this._resetAndLoadRecipes().then(
return this._resetAndLoadRecipes(scrollToIndex).then(
() => {
this.loading = false;
},
Expand All @@ -283,17 +287,19 @@ export class HomePage {
);
}

async _resetAndLoadRecipes() {
async _resetAndLoadRecipes(scrollToIndex?: number) {
if (this.searchText && this.searchText.trim().length > 0) {
await this.search(this.searchText);
} else {
await this.loadRecipes(0, this.fetchPerPage);
}

return this.datasource.adapter.reset();
this.datasource.settings!.startIndex = scrollToIndex || 0;
await this.datasource.adapter.reset();
}

resetRecipes() {
this.datasource.settings!.startIndex = 0;
this.recipes = [];
this.lastRecipeCount = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { SelectableItem } from "../../../components/select-multiple-items/select
import { FeatureFlagService } from "../../../services/feature-flag.service";
import { IS_SELFHOST } from "@recipesage/frontend/src/environments/environment";
import { ErrorHandlers } from "../../../services/http-error-handler.service";
import { EventName, EventService } from "../../../services/event.service";

@Component({
selector: "page-edit-recipe",
Expand Down Expand Up @@ -79,6 +80,7 @@ export class EditRecipePage {
private recipeService: RecipeService,
private imageService: ImageService,
private capabilitiesService: CapabilitiesService,
private events: EventService,
private featureFlagService: FeatureFlagService,
) {
const recipeId = this.route.snapshot.paramMap.get("recipeId") || "new";
Expand Down Expand Up @@ -215,7 +217,7 @@ export class EditRecipePage {
}

async _create(title: string) {
return this.trpcService.handle(
const response = await this.trpcService.handle(
this.trpcService.trpc.recipes.createRecipe.mutate({
title,
description: this.recipe.description || "",
Expand All @@ -233,10 +235,14 @@ export class EditRecipePage {
labelIds: this.selectedLabels.map((label) => label.id),
}),
);

this.events.publish(EventName.RecipeCreated);

return response;
}

async _update(id: string, title: string) {
return this.trpcService.handle(
const response = await this.trpcService.handle(
this.trpcService.trpc.recipes.updateRecipe.mutate({
id,
title,
Expand All @@ -255,6 +261,10 @@ export class EditRecipePage {
labelIds: this.selectedLabels.map((label) => label.id),
}),
);

this.events.publish(EventName.RecipeUpdated);

return response;
}

async _save() {
Expand All @@ -271,7 +281,9 @@ export class EditRecipePage {

this.markAsClean();

this.navCtrl.navigateRoot(RouteMap.RecipePage.getPath(response.id));
this.navCtrl.navigateForward(RouteMap.RecipePage.getPath(response.id), {
replaceUrl: true,
});
}

async _saveCheckConflict() {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/assets/i18n/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@
"pages.assistant.title": "Cooking Assistant",
"pages.assistant.welcome.1": "Welcome to the RecipeSage cooking assistant!",
"pages.assistant.welcome.2": "The cooking assistant is an AI model that can respond to your cooking questions and help create recipes.",
"pages.assistant.welcome.3": "The cooking assistant has a message limit of 5 messages/day because of the high costs to run the AI. This limit is increased to 50 messages/day for contributors.",
"pages.assistant.welcome.3": "The cooking assistant has a message limit of 5 messages/day because of the high costs to run the AI. This limit is increased to 75 messages/day for contributors.",
"pages.assistant.welcome.documentation": "Please read the assistant documentation",
"pages.assistant.messageLimit": "Maximum messages reached (sorry, it's costly!). Message count resets at 0:00GMT.",

Expand Down
2 changes: 1 addition & 1 deletion packages/util/server/src/ml/assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class Assistant {
},
});

const messageLimit = moreMessages ? 50 : 5;
const messageLimit = moreMessages ? 75 : 5;

const isOverLimit = todayMessageCount >= messageLimit;

Expand Down
4 changes: 1 addition & 3 deletions packages/util/server/src/ml/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import {
import { RSRunnableFunction } from "./chatFunctions";

export enum SupportedGPTModel {
GPT35Turbo = "gpt-3.5-turbo-0125",
GPT4Turbo = "gpt-4-turbo-2024-04-09",
GPT4OMini = "gpt-4o-mini-2024-07-18",
GPT4O = "gpt-4o-2024-05-13",
GPT4O = "gpt-4o-2024-08-06",
}

export class OpenAIHelper {
Expand Down

0 comments on commit 9054b6a

Please sign in to comment.