Skip to content
Permalink
Browse files

1.2.0

  • Loading branch information...
piotrzdziarski committed Jun 11, 2019
1 parent fea9251 commit eef71dc0cf1962d9bd73e3d295fe3e108a23593b
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import "./css/demo.css";
import FsLightbox from '../src/FsLightbox.jsx';
import FsLightbox from '../index';
import { TEST_YOUTUBE_URL, testVideoURL, testYoutubeURL } from "./demoData";

class DemoComponent extends Component {
@@ -44,18 +44,21 @@ class DemoComponent extends Component {
toggler={ this.state.toggler }
urls={ [
'../demo/images/5.jpg',
'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4',
'https://escalante-mkt-imgs.s3-us-west-2.amazonaws.com/TimeSheets/screenshot1.png',
// "invalid",
TEST_YOUTUBE_URL,
// testVideoURL,
"https://images.pexels.com/photos/2118563/pexels-photo-2118563.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
"file:///",
"../demo/images/3.jpeg"
] }
types={ [
'image',
'image'
] }
videosPosters={ [
// "../demo/images/1.jpeg"
] }
disableLocalStorage={ false }
disableLocalStorage={ true }
// onClose={ () => console.log('onClose') }
// onInit={ () => console.log('onInit') }
// onOpen={ () => console.log('onOpen') }

Large diffs are not rendered by default.

@@ -1,6 +1,6 @@
{
"name": "fslightbox-react",
"version": "1.1.1",
"version": "1.2.0",
"description": "React version of Fullscreen Lightbox.",
"main": "index.js",
"scripts": {
@@ -183,6 +183,7 @@ class FsLightbox extends Component {
FsLightbox.propTypes = {
toggler: PropTypes.bool.isRequired,
urls: PropTypes.array.isRequired,
types: PropTypes.array,
disableLocalStorage: PropTypes.bool,
onOpen: PropTypes.func,
onClose: PropTypes.func,
@@ -1,4 +1,5 @@
import { SOURCES_TYPES_KEY } from "../../../constants/localStorageConstants";
import { assignToObject } from "../../../helpers/objects/assignToObject";

/**
* @constructor
@@ -49,7 +50,7 @@ export function CreatingSourcesLocalStorageManager(fsLightbox) {

const ifAllNewTypesAreDetectedStoreAllTypesToLocalStorage = () => {
if (newSourceTypesToDetect === 0) {
Object.assign(decodedSourceTypes, newTypes);
assignToObject(decodedSourceTypes, newTypes);
localStorage.setItem(SOURCES_TYPES_KEY, JSON.stringify(decodedSourceTypes));
}
};
@@ -4,26 +4,45 @@ import { DetectedTypeActions } from "../types/DetectedTypeActions";

export function createSources(
{
props: { urls },
props: {
urls,
types: typesSetManuallyByClient
},
injector: { injectDependency }
}
) {
const detectedTypeActions = injectDependency(DetectedTypeActions);
const localStorageManager = injectDependency(CreatingSourcesLocalStorageManager);
let sourceTypeFromLocalStorage;
let getTypeSetManuallyByClient;
let sourceTypeRetrievedWithoutXhr;
let sourceIndex;
setUpGetTypeSetManuallyByClient();

for (let i = 0; i < urls.length; i++) {
sourceIndex = i;
sourceTypeFromLocalStorage = localStorageManager.getSourceTypeFromLocalStorageByUrl(urls[sourceIndex]);
(sourceTypeFromLocalStorage) ?
callActionsForSourceTypeFromLocalStorage() :
let typeSetManuallyByClient = getTypeSetManuallyByClient(i);
// if client set type it's always the most important one
if (typeSetManuallyByClient) {
sourceTypeRetrievedWithoutXhr = typeSetManuallyByClient;
callActionsForSourceTypeRetrievedWithoutXhr();
continue;
}
sourceTypeRetrievedWithoutXhr = localStorageManager.getSourceTypeFromLocalStorageByUrl(urls[sourceIndex]);
(sourceTypeRetrievedWithoutXhr) ?
callActionsForSourceTypeRetrievedWithoutXhr() :
retrieveTypeWithXhrAndCallActions();
}

function callActionsForSourceTypeFromLocalStorage() {
function setUpGetTypeSetManuallyByClient() {
// if user didn't set types prop we need to prevent from retrieving indexes from undefined
(typeof typesSetManuallyByClient !== "object") ?
getTypeSetManuallyByClient = () => null :
getTypeSetManuallyByClient = (i) => typesSetManuallyByClient[i]
}

function callActionsForSourceTypeRetrievedWithoutXhr() {
detectedTypeActions.runActionsForSourceTypeAndIndex(
sourceTypeFromLocalStorage, sourceIndex
sourceTypeRetrievedWithoutXhr, sourceIndex
);
}

@@ -0,0 +1,10 @@
/**
* This function assigns to object properties from second one
* @param { Object } object
* @param { Object } toAssign
*/
export function assignToObject(object, toAssign) {
for (let toAssignPropertyName in toAssign) {
object[toAssignPropertyName] = toAssign[toAssignPropertyName];
}
}
@@ -0,0 +1,20 @@
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import FsLightbox from "../../src/FsLightbox";
import { testUrls } from "../__tests-helpers__/testVariables";

// simulating server behaviour - deleting window and document
delete global.window;
delete global.document;

it('should not throw error when lightbox is closed on init', () => {
expect(() => {
ReactDOMServer.renderToString(<FsLightbox toggler={ false } urls={ testUrls }/>)
}).not.toThrowError();
});

it('should not throw error when lightbox is open on init', () => {
expect(() => {
ReactDOMServer.renderToString(<FsLightbox toggler={ true } urls={ testUrls }/>)
}).not.toThrowError();
});

0 comments on commit eef71dc

Please sign in to comment.
You can’t perform that action at this time.