Merge pull request #23 from ente-io/bhasaad

Bhasaad
This commit is contained in:
Vishnu Mohandas 2021-02-17 15:18:38 +05:30 committed by GitHub
commit 05f29480a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 59 additions and 68 deletions

View file

@ -17,7 +17,7 @@ export default function FullScreenDropZone({
showModal,
closeModal,
}: Props) {
const closeTimer = useRef<number>();
const closeTimer = useRef<NodeJS.Timeout>();
const clearTimer = () => {
if (closeTimer.current) {

View file

@ -15,13 +15,14 @@ import DownloadManger from 'services/downloadManager';
interface Iprops {
isOpen: boolean;
items: any[];
options?: Object;
currentIndex?: number;
onClose?: () => void;
gettingData?: (instance: any, index: number, item: file) => void;
id?: string;
className?: string;
favItemIds: Set<number>;
setFavItemIds: (favItemIds: Set<number>) => void;
loadingBar: any;
}
function PhotoSwipe(props: Iprops) {
@ -58,7 +59,12 @@ function PhotoSwipe(props: Iprops) {
}
const openPhotoSwipe = () => {
const { items, options } = props;
const { items, currentIndex } = props;
const options = {
history: false,
maxSpreadZoom: 5,
index: currentIndex,
};
let photoSwipe = new Photoswipe(
pswpElement,
PhotoswipeUIDefault,
@ -125,9 +131,12 @@ function PhotoSwipe(props: Iprops) {
}
};
const downloadFile = async (file) => {
const { loadingBar } = props;
const a = document.createElement('a');
a.style.display = 'none';
loadingBar.current.continuousStart();
a.href = await DownloadManger.getFile(file);
loadingBar.current.complete();
a.download = file.metadata['title'];
document.body.appendChild(a);
a.click();

View file

@ -114,6 +114,7 @@ const GlobalStyles = createGlobalStyle`
cursor: pointer;
background-size: cover;
border: none;
}
.btn-primary {
background: #2dc262;
border-color: #29a354;

View file

@ -126,6 +126,7 @@ export default function Credentials() {
errors.passphrase
)}
disabled={loading}
autoFocus={true}
/>
<Form.Control.Feedback type="invalid">
{errors.passphrase}

View file

@ -4,7 +4,7 @@ import styled from 'styled-components';
interface CollectionProps {
collections: collection[];
selected?: Number;
selected?: number;
selectCollection: (id?: number) => void;
}

View file

@ -1,13 +1,11 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { useRouter } from 'next/router';
import { getKey, SESSION_KEYS } from 'utils/storage/sessionStorage';
import { file, syncData, localFiles } from 'services/fileService';
import { getData, LS_KEYS } from 'utils/storage/localStorage';
import PreviewCard from './components/PreviewCard';
import { getActualKey, getToken } from 'utils/common/key';
import styled from 'styled-components';
import PhotoSwipe from 'components/PhotoSwipe/PhotoSwipe';
import { Options } from 'photoswipe';
import AutoSizer from 'react-virtualized-auto-sizer';
import { VariableSizeList as List } from 'react-window';
import LoadingBar from 'react-top-loading-bar';
@ -21,6 +19,7 @@ import {
getCollectionAndItsLatestFile,
getFavItemIds,
getLocalCollections,
getCollectionUpdationTime,
} from 'services/collectionService';
import constants from 'utils/strings/constants';
import ErrorAlert from './components/ErrorAlert';
@ -110,23 +109,21 @@ export default function Gallery(props) {
const [data, setData] = useState<file[]>();
const [favItemIds, setFavItemIds] = useState<Set<number>>();
const [open, setOpen] = useState(false);
const [options, setOptions] = useState<Options>({
history: false,
maxSpreadZoom: 5,
});
const [currentIndex, setCurrentIndex] = useState<number>(0);
const fetching: { [k: number]: boolean } = {};
const [errorCode, setErrorCode] = useState<number>(null);
const [sinceTime, setSinceTime] = useState(0);
const [isFirstLoad, setIsFirstLoad] = useState(false);
const [progress, setProgress] = useState(0);
const loadingBar = useRef(null);
useEffect(() => {
const key = getKey(SESSION_KEYS.ENCRYPTION_KEY);
if (!key) {
router.push('/');
return;
}
const main = async () => {
setIsFirstLoad(await getCollectionUpdationTime() == 0);
const data = await localFiles();
const collections = await getLocalCollections();
const collectionAndItsLatestFile = await getCollectionAndItsLatestFile(
@ -139,9 +136,10 @@ export default function Gallery(props) {
const favItemIds = await getFavItemIds(data);
setFavItemIds(favItemIds);
data.length == 0 ? setProgress(20) : setProgress(80);
loadingBar.current.continuousStart();
await syncWithRemote();
setProgress(100);
loadingBar.current.complete();
setIsFirstLoad(false);
};
main();
props.setUploadButtonView(true);
@ -222,10 +220,7 @@ export default function Gallery(props) {
};
const onThumbnailClick = (index: number) => () => {
setOptions({
...options,
index,
});
setCurrentIndex(index);
setOpen(true);
};
@ -286,20 +281,6 @@ export default function Gallery(props) {
if (!data) {
return <div />;
}
if (data.length == 0 && progress != 0) {
return (
<div className="text-center">
<LoadingBar
color="#2dc262"
progress={progress}
onLoaderFinished={() => setProgress(0)}
/>
<Alert variant="primary">
{constants.INITIAL_LOAD_DELAY_WARNING}
</Alert>
</div>
);
}
const selectCollection = (id?: number) => {
const href = `/gallery?collection=${id || ''}`;
@ -336,12 +317,16 @@ export default function Gallery(props) {
return (
<>
<LoadingBar color="#2dc262" ref={loadingBar} />
{isFirstLoad && (
<div className="text-center">
<Alert variant="primary">
{constants.INITIAL_LOAD_DELAY_WARNING}
</Alert>
</div>
)}
<ErrorAlert errorCode={errorCode} />
<LoadingBar
color="#2dc262"
progress={progress}
onLoaderFinished={() => setProgress(0)}
/>
<Collections
collections={collections}
selected={Number(router.query.collection)}
@ -487,11 +472,12 @@ export default function Gallery(props) {
<PhotoSwipe
isOpen={open}
items={filteredData}
options={options}
currentIndex={currentIndex}
onClose={handleClose}
gettingData={getSlideData}
favItemIds={favItemIds}
setFavItemIds={setFavItemIds}
loadingBar={loadingBar}
/>
</Container>
) : (

View file

@ -1,11 +1,11 @@
import axios, { AxiosRequestConfig } from 'axios';
interface IHTTPHeaders {
[headerKey: string]: string;
[headerKey: string]: any;
}
interface IQueryPrams {
[paramName: string]: string;
[paramName: string]: any;
}
/**

View file

@ -91,7 +91,7 @@ const getCollectionSecrets = async (
const getCollections = async (
token: string,
sinceTime: string,
sinceTime: number,
key: string
): Promise<collection[]> => {
try {
@ -117,10 +117,13 @@ export const getLocalCollections = async (): Promise<collection[]> => {
return collections;
};
export const getCollectionUpdationTime = async (): Promise<number> => {
return await localForage.getItem<number>(COLLECTION_UPDATION_TIME) ?? 0;
}
export const syncCollections = async (token: string, key: string) => {
const localCollections = await getLocalCollections();
const lastCollectionUpdationTime =
(await localForage.getItem<string>(COLLECTION_UPDATION_TIME)) ?? '0';
const lastCollectionUpdationTime = await getCollectionUpdationTime();
const updatedCollections =
(await getCollections(token, lastCollectionUpdationTime, key)) || [];
if (updatedCollections.length == 0) {
@ -163,7 +166,6 @@ export const getCollectionAndItsLatestFile = (
files: file[]
): CollectionAndItsLatestFile[] => {
const latestFile = new Map<number, file>();
const collectionMap = new Map<number, collection>();
files.forEach((file) => {
if (!latestFile.has(file.collectionID)) {

View file

@ -123,9 +123,9 @@ export const getFiles = async (
resp = await HTTPService.get(
`${ENDPOINT}/collections/diff`,
{
collectionID: collection.id.toString(),
sinceTime: time.toString(),
limit: limit.toString(),
collectionID: collection.id,
sinceTime: time,
limit: limit,
},
{
'X-Auth-Token': token,
@ -146,7 +146,7 @@ export const getFiles = async (
);
if (resp.data.diff.length) {
time = resp.data.diff.slice(-1)[0].updationTime.toString();
time = resp.data.diff.slice(-1)[0].updationTime;
}
} while (resp.data.diff.length === limit);
return await Promise.all(promises);

View file

@ -498,7 +498,7 @@ class UploadService {
count: Math.min(
50,
(this.totalFileCount - this.filesCompleted) * 2
).toString(),
),
},
{ 'X-Auth-Token': token }
);
@ -519,7 +519,7 @@ class UploadService {
file: Uint8Array | string
): Promise<string> {
try {
const fileSize = file.length.toString();
const fileSize = file.length;
await HTTPService.put(fileUploadURL.url, file, null, {
contentLengthHeader: fileSize,
});
@ -571,23 +571,15 @@ class UploadService {
let latDegree: number, latMinute: number, latSecond: number;
let lonDegree: number, lonMinute: number, lonSecond: number;
if (exifData.GPSLatitude[0].numerator) {
latDegree = exifData.GPSLatitude[0].numerator;
latMinute = exifData.GPSLatitude[1].numerator;
latSecond = exifData.GPSLatitude[2].numerator;
lonDegree = exifData.GPSLongitude[0].numerator;
lonMinute = exifData.GPSLongitude[1].numerator;
lonSecond = exifData.GPSLongitude[2].numerator;
} else {
latDegree = exifData.GPSLatitude[0];
latMinute = exifData.GPSLatitude[1];
latSecond = exifData.GPSLatitude[2];
latDegree = exifData.GPSLatitude[0];
latMinute = exifData.GPSLatitude[1];
latSecond = exifData.GPSLatitude[2];
lonDegree = exifData.GPSLongitude[0];
lonMinute = exifData.GPSLongitude[1];
lonSecond = exifData.GPSLongitude[2];
lonDegree = exifData.GPSLongitude[0];
lonMinute = exifData.GPSLongitude[1];
lonSecond = exifData.GPSLongitude[2];
}
var latDirection = exifData.GPSLatitudeRef;
var lonDirection = exifData.GPSLongitudeRef;

View file

@ -50,7 +50,7 @@ const englishConstants = {
SELECT_COLLECTION: `select an album to upload to`,
CREATE_COLLECTION: `create album`,
CLOSE: 'close',
NOTHING_HERE: `nothing to see here! 👀`,
NOTHING_HERE: `nothing to see here, yet 👀`,
UPLOAD: {
0: 'preparing to upload',
1: 'reading google metadata files',