<commit_before>import BaseStore from 'fluxible/addons/BaseStore';
import RouteStore from './RouteStore';
import { Microservices } from '../configs/microservices';

class ApplicationStore extends BaseStore {
    constructor(dispatcher) {
        super(dispatcher);
        this.pageTitle = '';
        this.pageThumbnail = '/assets/images/slideWiki-logo-linear.png'; //can add a default image here
        this.pageDescription = '';
        this.showActivationMessage = false;
        //this.frozen = false;
    }
    handlePageTitle(payload) {
        this.dispatcher.waitFor(RouteStore, () => {
            //if (!this.frozen || payload.allowUnfreeze) {
            this.pageTitle = payload.pageTitle;
            //    this.frozen = payload.frozen;
            //}
            this.emitChange();
        });
    }
    updatePageMetadata(payload) {
        this.dispatcher.waitFor(RouteStore, () => {
            let thumbnailTheme = payload.thumbnailTheme || 'default';
            this.pageThumbnail = Microservices.file.uri + '/thumbnail/slide/' + payload.thumbnailID + '/' + thumbnailTheme;
            this.pageDescription = payload.description;
            console.warn('!!! thumbnail:', this.pageThumbnail);
            this.emitChange();
        });
    }
    handleActivationMessage(payload) {
        this.showActivationMessage = true;
        this.emitChange();
    }
    getPageTitle() {
        return this.pageTitle;
    }
    getPageThumbnail() {
        return this.pageThumbnail;
    }
    getPageDescription() {
        // remove line breaks for page description
        return this.pageDescription.replace(/(\r\n\t|\n|\r\t)/gm,' ');
    }
    getActivationMessage(){
        return this.showActivationMessage;
    }
    dehydrate() {
        return {
            pageTitle: this.pageTitle,
            pageThumbnail: this.pageThumbnail,
            pageDescription: this.pageDescription,
            showActivationMessage: this.showActivationMessage,
        };
    }
    rehydrate(state) {
        this.pageTitle = state.pageTitle;
        this.pageThumbnail = state.pageThumbnail;
        this.pageDescription = state.pageDescription;
        this.showActivationMessage = state.showActivationMessage;
    }
}

ApplicationStore.storeName = 'ApplicationStore';
ApplicationStore.handlers = {
    'UPDATE_PAGE_TITLE': 'handlePageTitle',
    'LOAD_DECK_METADATA_SUCCESS': 'updatePageMetadata',<commit_msg>Prevent error when no description is provided<commit_after>import BaseStore from 'fluxible/addons/BaseStore';
import RouteStore from './RouteStore';
import { Microservices } from '../configs/microservices';

class ApplicationStore extends BaseStore {
    constructor(dispatcher) {
        super(dispatcher);
        this.pageTitle = '';
        this.pageThumbnail = '/assets/images/slideWiki-logo-linear.png'; //can add a default image here
        this.pageDescription = '';
        this.showActivationMessage = false;
        //this.frozen = false;
    }
    handlePageTitle(payload) {
        this.dispatcher.waitFor(RouteStore, () => {
            //if (!this.frozen || payload.allowUnfreeze) {
            this.pageTitle = payload.pageTitle;
            //    this.frozen = payload.frozen;
            //}
            this.emitChange();
        });
    }
    updatePageMetadata(payload) {
        this.dispatcher.waitFor(RouteStore, () => {
            let thumbnailTheme = payload.thumbnailTheme || 'default';
            this.pageThumbnail = Microservices.file.uri + '/thumbnail/slide/' + payload.thumbnailID + '/' + thumbnailTheme;
            if (payload.description !== undefined) {
                this.pageDescription = payload.description;
            }
            console.warn('!!! thumbnail:', this.pageThumbnail);
            this.emitChange();
        });
    }
    handleActivationMessage(payload) {
        this.showActivationMessage = true;
        this.emitChange();
    }
    getPageTitle() {
        return this.pageTitle;
    }
    getPageThumbnail() {
        return this.pageThumbnail;
    }
    getPageDescription() {
        // remove line breaks for page description
        if (this.pageDescription !== undefined) {
            return this.pageDescription.replace(/(\r\n\t|\n|\r\t)/gm,' ');
        }
        
        return '';    
    }
    getActivationMessage(){
        return this.showActivationMessage;
    }
    dehydrate() {
        return {
            pageTitle: this.pageTitle,
            pageThumbnail: this.pageThumbnail,
            pageDescription: this.pageDescription,
            showActivationMessage: this.showActivationMessage,
        };
    }
    rehydrate(state) {
        this.pageTitle = state.pageTitle;
        this.pageThumbnail = state.pageThumbnail;
        this.pageDescription = state.pageDescription;
        this.showActivationMessage = state.showActivationMessage;
    }
}

ApplicationStore.storeName = 'ApplicationStore';
ApplicationStore.handlers = {
    'UPDATE_PAGE_TITLE': 'handlePageTitle',
    'LOAD_DECK_METADATA_SUCCESS': 'updatePageMetadata',
{'fraction_non_alphanumeric': 0.11481261154074955, 'fraction_numerical': 0.0, 'mean_word_length': 2.3761713520749663, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5600045', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1385, 'n_words': 226}