Skip to content

armgit / ente

Public Imported from GitHub
0

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

[web][photos] Add upload button to hidden albums section

Anand Baburajand5e7d515d931
diff --git a/web/apps/photos/src/components/Collections/AllAlbums.tsx b/web/apps/photos/src/components/Collections/AllAlbums.tsx
index c9c598725c..48eb83a04c 100644
--- a/web/apps/photos/src/components/Collections/AllAlbums.tsx
+++ b/web/apps/photos/src/components/Collections/AllAlbums.tsx
@@ -31,7 +31,10 @@ import {
LargeTileCreateNewButton,
LargeTileTextOverlay,
} from "ente-new/photos/components/Tiles";
-import { createAlbum } from "ente-new/photos/services/collection";
+import {
+ createAlbum,
+ createHiddenAlbum,
+} from "ente-new/photos/services/collection";
import type {
CollectionsSortBy,
CollectionSummary,
@@ -96,7 +99,9 @@ export const AllAlbums: React.FC<AllAlbums> = ({
void (async () => {
try {
- const newAlbum = await createAlbum(albumName);
+ const newAlbum = isInHiddenSection
+ ? await createHiddenAlbum(albumName)
+ : await createAlbum(albumName);
await onRemotePull();
// Show custom toast with both buttons
diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsx
index a034697ec3..9d425e35d9 100644
--- a/web/apps/photos/src/components/Upload.tsx
+++ b/web/apps/photos/src/components/Upload.tsx
@@ -65,6 +65,7 @@ import type { RemotePullOpts } from "ente-new/photos/components/gallery";
import { downloadAppDialogAttributes } from "ente-new/photos/components/utils/download";
import {
createAlbum,
+ createHiddenAlbum,
savedAllCollections,
savedNormalCollections,
} from "ente-new/photos/services/collection";
@@ -159,6 +160,13 @@ interface UploadProps {
* the Upload component wants to prompt the user to log in again.
*/
onShowSessionExpiredDialog: () => void;
+ /**
+ * If true, the upload is being initiated from the hidden albums section.
+ *
+ * When set, the collection selector will only show hidden albums, and any
+ * new albums created will be hidden albums.
+ */
+ isInHiddenSection?: boolean;
}
type UploadType = "files" | "folders" | "zips";
@@ -593,6 +601,7 @@ export const Upload: React.FC<UploadProps> = ({
onOpenCollectionSelector?.({
action: "upload",
activeCollectionID: props.activeCollection?.id,
+ showHiddenCollections: props.isInHiddenSection,
onSelectCollection: uploadFilesToExistingCollection,
onCreateCollection: showNextModal,
onCancel: handleCollectionSelectorCancel,
@@ -638,6 +647,7 @@ export const Upload: React.FC<UploadProps> = ({
mapping: CollectionMapping,
collectionName?: string,
includeHiddenCollections?: boolean,
+ createHidden?: boolean,
) => {
preCollectionCreationAction();
let uploadItemsWithCollection: UploadItemWithCollection[] = [];
@@ -676,6 +686,7 @@ export const Upload: React.FC<UploadProps> = ({
collectionName,
user!,
existingCollections,
+ createHidden,
);
collections.push(collection);
uploadItemsWithCollection = [
@@ -822,7 +833,12 @@ export const Upload: React.FC<UploadProps> = ({
};
const uploadToSingleNewCollection = (collectionName: string) => {
- uploadFilesToNewCollections("root", collectionName);
+ uploadFilesToNewCollections(
+ "root",
+ collectionName,
+ undefined,
+ props.isInHiddenSection,
+ );
};
const cancelUploads = () => {
@@ -868,6 +884,8 @@ export const Upload: React.FC<UploadProps> = ({
mapping,
importSuggestion.rootFolderName ||
t("autogenerated_default_album_name"),
+ undefined,
+ props.isInHiddenSection,
);
return (
@@ -1056,6 +1074,7 @@ const matchExistingOrCreateAlbum = async (
albumName: string,
user: LocalUser,
existingCollections: Collection[],
+ createHidden?: boolean,
) => {
for (const collection of existingCollections) {
if (
@@ -1078,7 +1097,9 @@ const matchExistingOrCreateAlbum = async (
}
}
- const collection = await createAlbum(albumName);
+ const collection = createHidden
+ ? await createHiddenAlbum(albumName)
+ : await createAlbum(albumName);
log.info(`Created new album ${albumName} with id ${collection.id}`);
return collection;
};
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 251391d3ae..24d167d41f 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -1570,7 +1570,11 @@ const Page: React.FC = () => {
open={openCollectionSelector}
onClose={handleCloseCollectionSelector}
attributes={collectionSelectorAttributes}
- collectionSummaries={normalCollectionSummaries}
+ collectionSummaries={
+ collectionSelectorAttributes?.showHiddenCollections
+ ? state.hiddenCollectionSummaries
+ : normalCollectionSummaries
+ }
collectionForCollectionSummaryID={(id) =>
findCollectionCreatingUncategorizedIfNeeded(
state.collections,
@@ -1632,6 +1636,7 @@ const Page: React.FC = () => {
) : barMode == "hidden-albums" ? (
<HiddenSectionNavbarContents
onBack={() => dispatch({ type: "showAlbums" })}
+ onUpload={openUploader}
/>
) : (
<NormalNavbarContents
@@ -1710,6 +1715,7 @@ const Page: React.FC = () => {
onUploadFile={(file) => dispatch({ type: "uploadFile", file })}
onShowPlanSelector={showPlanSelector}
onShowSessionExpiredDialog={showSessionExpiredDialog}
+ isInHiddenSection={barMode == "hidden-albums"}
/>
<Sidebar
{...sidebarVisibilityProps}
@@ -1921,11 +1927,12 @@ const UploadButton: React.FC<ButtonishProps> = ({ onClick }) => {
interface HiddenSectionNavbarContentsProps {
onBack: () => void;
+ onUpload: () => void;
}
const HiddenSectionNavbarContents: React.FC<
HiddenSectionNavbarContentsProps
-> = ({ onBack }) => (
+> = ({ onBack, onUpload }) => (
<Stack
direction="row"
sx={(theme) => ({
@@ -1939,6 +1946,7 @@ const HiddenSectionNavbarContents: React.FC<
<ArrowBackIcon />
</IconButton>
<Typography sx={{ flex: 1 }}>{t("section_hidden")}</Typography>
+ <UploadButton onClick={onUpload} />
</Stack>
);
diff --git a/web/packages/new/photos/components/CollectionSelector.tsx b/web/packages/new/photos/components/CollectionSelector.tsx
index 5ab25b2cb4..fd6734a897 100644
--- a/web/packages/new/photos/components/CollectionSelector.tsx
+++ b/web/packages/new/photos/components/CollectionSelector.tsx
@@ -68,6 +68,12 @@ export interface CollectionSelectorAttributes {
* specific collection and might want to upload to it.
*/
activeCollectionID?: number;
+ /**
+ * If true, only show hidden albums in the collection selector.
+ *
+ * This is used when uploading from the hidden albums section.
+ */
+ showHiddenCollections?: boolean;
/**
* Callback invoked when the user selects the option to create a new
* collection.
diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.ts
index 2f11f7d093..ba51dd90dd 100644
--- a/web/packages/new/photos/services/collection.ts
+++ b/web/packages/new/photos/services/collection.ts
@@ -67,6 +67,16 @@ const favoritesCollectionName = "Favorites";
export const createAlbum = (albumName: string) =>
createCollection(albumName, "album");
+/**
+ * Create a new hidden album on remote, and return its local representation.
+ *
+ * Remote only, does not modify local state.
+ *
+ * @param albumName The name to use for the new hidden album.
+ */
+export const createHiddenAlbum = (albumName: string) =>
+ createCollection(albumName, "album", { visibility: ItemVisibility.hidden });
+
/**
* Create a new collection on remote, and return its local representation.
*