Skip to content

Commit

Permalink
feat(Album View Page): Save photoLink in memories for local
Browse files Browse the repository at this point in the history
  • Loading branch information
danactive committed Mar 23, 2020
1 parent f1797f4 commit 9dee9af
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 13 deletions.
1 change: 1 addition & 0 deletions ui/app/containers/AlbumViewPage/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export const LOAD_THUMBS_SUCCESS = 'app/AlbumViewPage/LOAD_THUMBS_SUCCESS';
export const NEXT_MEMORY = 'app/AlbumViewPage/NEXT_MEMORY';
export const PREV_MEMORY = 'app/AlbumViewPage/PREV_MEMORY';
export const PAGE_SIZE = 8;
export const PRELOAD_PHOTO = 'app/AlbumView/PRELOAD_PHOTO';
6 changes: 6 additions & 0 deletions ui/app/containers/AlbumViewPage/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
LOAD_NEXT_THUMB_PAGE_ERROR,
LOAD_THUMBS_SUCCESS,
} from './constants';
import { LOAD_PHOTO_SUCCESS } from '../App/constants';

export const initialState = {
albumLoading: true,
Expand Down Expand Up @@ -60,6 +61,11 @@ const reducer = (state = initialState, action) => produce(state, (draft) => {
delete draft.hasMore;
break;
}

case LOAD_PHOTO_SUCCESS: {
draft.memoryId = action.id;
break;
}
}
});

Expand Down
21 changes: 20 additions & 1 deletion ui/app/containers/AlbumViewPage/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import {
import normalizeError from '../../utils/error';
import request from '../../utils/request';

import { LOAD_ALBUM, LOAD_NEXT_THUMB_PAGE, PAGE_SIZE } from './constants';
import {
LOAD_ALBUM,
LOAD_ALBUM_SUCCESS,
LOAD_NEXT_THUMB_PAGE,
PAGE_SIZE,
} from './constants';
import {
albumLoadSuccess,
albumLoadError,
Expand Down Expand Up @@ -188,8 +193,22 @@ export function* getThumbPaths() {
}
}

export function* preloadFirst() {
// const {
// page,
// memories,
// album,
// gallery,
// host,
// } = yield select(selectNextPage);
//
// console.log('page', page);
// console.log('memories', memories);
}

// ROOT saga manages WATCHER lifecycle
export default function* AlbumViewPageSagaWatcher() {
yield takeLatest(LOAD_ALBUM, getAlbumFile);
yield takeLatest(LOAD_ALBUM_SUCCESS, preloadFirst);
yield takeLatest(LOAD_NEXT_THUMB_PAGE, getThumbPaths);
}
7 changes: 6 additions & 1 deletion ui/app/containers/App/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ export function chooseMemory(id) {
}

export function photoLoadSuccess({
gallery, album, id, photoLink,
host,
gallery,
album,
id,
photoLink,
}) {
return {
type: LOAD_PHOTO_SUCCESS,
host,
gallery,
album,
id,
Expand Down
3 changes: 3 additions & 0 deletions ui/app/containers/App/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ const appReducer = (state = initialState, action) => produce(state, (draft) => {
}

case LOAD_PHOTO_SUCCESS: {
const memoryIndex = draft[action.host][action.gallery][action.album].memories.findIndex(memory => memory.id === action.id);
draft[action.host][action.gallery][action.album].memories[memoryIndex].photoLink = action.photoLink;

draft.currentMemory.photoLink = action.photoLink;
break;
}
Expand Down
63 changes: 52 additions & 11 deletions ui/app/containers/InfiniteThumbs/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import normalizeError from '../../utils/error';

import { CHOOSE_MEMORY } from '../App/constants';
import { makeSelectCurrentMemory } from '../App/selectors';
import { makeSelectMemories } from '../AlbumViewPage/selectors';
import { photoLoadError, photoLoadSuccess } from '../App/actions';
import {
NEXT_MEMORY,
Expand All @@ -34,40 +35,80 @@ export const argsPhotoXmlPath = ({ gallery, filename }) => {


// saga WORKER for CHOOSE_MEMORY
export function* getPhotoPathsOnDropbox({ currentMemory, album, gallery }) {
export function* getPhotoPathsOnDropbox({
currentMemory,
host,
gallery,
album,
}) {
try {
const { filename, id } = currentMemory;
const xmlUrl = yield call([dbx, 'filesGetTemporaryLink'], argsPhotoXmlPath({ gallery, filename }));

yield put(photoLoadSuccess({
gallery, album, id, photoLink: xmlUrl.link,
id,
photoLink: xmlUrl.link,
host,
gallery,
album,
}));
} catch (error) {
yield put(photoLoadError(normalizeError(error)));
}
}

export function* getPhotoPathsLocally({ currentMemory, album, gallery }) {
export function* getPhotoPathsLocally({
id,
currentMemory,
host,
gallery,
album,
}) {
yield put(photoLoadSuccess({
id: new Date().toISOString(),
id,
photoLink: currentMemory.thumbLink.replace('thumbs', 'photos'),
host,
gallery,
album,
}));
}

export function* getPhotoPaths() {
const args = yield select(makeSelectCurrentMemory());
export function* getCurrentMemoryPhotoPath({ id }) {
const {
currentMemory,
host,
gallery,
album,
} = yield select(makeSelectCurrentMemory());

const memories = yield select(makeSelectMemories());
const { photoLink } = memories.find(memory => memory.id === id);

if (photoLink !== null) {
return;
}

if (args.host === 'dropbox') {
yield call(getPhotoPathsOnDropbox, args);
} else if (args.host === 'local') {
yield call(getPhotoPathsLocally, args);
if (host === 'dropbox') {
yield call(getPhotoPathsOnDropbox, {
id,
currentMemory,
host,
gallery,
album,
});
} else if (host === 'local') {
yield call(getPhotoPathsLocally, {
id,
currentMemory,
host,
gallery,
album,
});
}
}


// ROOT saga manages WATCHER lifecycle
export default function* InfiniteThumbsSagaWatcher() {
yield takeEvery([CHOOSE_MEMORY, NEXT_MEMORY, PREV_MEMORY], getPhotoPaths);
yield takeEvery([CHOOSE_MEMORY, NEXT_MEMORY, PREV_MEMORY], getCurrentMemoryPhotoPath);
}

0 comments on commit 9dee9af

Please sign in to comment.