Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

refractor(gallery):removed-unwanted-promise-resolvers

Aswin Asok5dde730d12e8
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 1ccea11e81..04ac370e5c 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -232,36 +232,19 @@ const Page: React.FC = () => {
const { show: showAlbumNameInput, props: albumNameInputVisibilityProps } =
useModalVisibility();
- // To resolve the pending promises when closing the AuthenticateUser modal
- const authenticateUserResolvers = useRef<{
- resolve?: () => void;
- reject?: (reason?: Error) => void;
- }>({});
-
- const resetAuthenticateUserResolvers = () => {
- authenticateUserResolvers.current = {};
- };
+ const onAuthenticateCallback = useRef<(() => void) | undefined>(undefined);
const authenticateUser = useCallback(
() =>
- new Promise<void>((resolve, reject) => {
- authenticateUserResolvers.current = { resolve, reject };
+ new Promise<void>((resolve) => {
+ onAuthenticateCallback.current = resolve;
showAuthenticateUser();
}),
- [showAuthenticateUser],
+ [],
);
- const handleAuthenticateUserSuccess = useCallback(() => {
- authenticateUserResolvers.current.resolve?.();
- resetAuthenticateUserResolvers();
- }, []);
-
const handleCloseAuthenticateUser = useCallback(() => {
authenticateUserVisibilityProps.onClose();
- authenticateUserResolvers.current.reject?.(
- new Error("authentication dismissed"),
- );
- resetAuthenticateUserResolvers();
}, [authenticateUserVisibilityProps.onClose]);
const handleSidebarClose = useCallback(() => {
@@ -1253,7 +1236,7 @@ const Page: React.FC = () => {
<AuthenticateUser
open={authenticateUserVisibilityProps.open}
onClose={handleCloseAuthenticateUser}
- onAuthenticate={handleAuthenticateUserSuccess}
+ onAuthenticate={onAuthenticateCallback.current!}
/>
<SingleInputDialog
{...albumNameInputVisibilityProps}
diff --git a/web/packages/new/photos/services/search/sidebar-search-registry.ts b/web/packages/new/photos/services/search/sidebar-search-registry.ts
index d180f48025..39fd2a07eb 100644
--- a/web/packages/new/photos/services/search/sidebar-search-registry.ts
+++ b/web/packages/new/photos/services/search/sidebar-search-registry.ts
@@ -55,7 +55,13 @@ const sidebarActions = (): SidebarAction[] => {
id: "account.subscription",
label: t("subscription"),
path: [accountCategory, t("subscription")],
- keywords: ["subscription", "plan", "upgrade", "billing"],
+ keywords: [
+ "subscription",
+ "plan",
+ "upgrade",
+ "billing",
+ "pricings",
+ ],
},
{
id: "shortcuts.uncategorized",
@@ -378,12 +384,26 @@ const matchesSearch = (
path: string[],
keywords: string[] = [],
) => {
+ const searchVariants = getSearchVariants(normalized);
const haystack = [label, ...path, ...keywords]
.filter(Boolean)
.map((s) => s.toLowerCase());
- const re = new RegExp("(^|[\\s.,!?\"'-_])" + escapeRegex(normalized));
+ const re = new RegExp(
+ "(^|[\\s.,!?\"'-_])(" +
+ searchVariants.map((s) => escapeRegex(s)).join("|") +
+ ")",
+ );
return haystack.some((h) => re.test(h));
};
+const getSearchVariants = (search: string) => {
+ const variants = new Set<string>([search]);
+ if (search.endsWith("ies")) variants.add(search.slice(0, -3) + "y");
+ if (search.endsWith("es")) variants.add(search.slice(0, -2));
+ if (search.endsWith("s")) variants.add(search.slice(0, -1));
+
+ return [...variants].filter((v) => v.length > 1);
+};
+
const escapeRegex = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");