import Axios from 'axios';
import {
    THREAD_REQUEST, 
    THREAD_LOADED, 
    THREAD_DESTROY,
    THREAD_POST_LOAD
} from '../constants';


function requestThread(threadID) {
	console.log("Action RequestThread wth ID:", threadID);
    return {
        type: THREAD_REQUEST,
        threadID
    }
}

function receiveThread(thread) {
    console.log("Action RecieveThread:", thread);
    return {
        type: THREAD_LOADED,
        payload: thread.data
    }
}

function destroyThread() {
    console.log('Destroying thread');
    document.querySelector('.thread').style.top = window.innerHeight + "px !important"
    console.info(window.innerHeight)
    console.info(document.querySelector('.thread').offsetTop)
    return {
        type: THREAD_DESTROY
    }
}

export function fetchThread(threadID, provider="4chan", boardID="g") {
    console.log(`Action FetchThread() to /${provider}/${boardID}/${threadID}`);
    return dispatch => {
        dispatch(requestThread(threadID));
        return Axios.get(`/${provider}/${boardID}/${threadID}`)
            .then(data => dispatch(receiveThread(data)))
            .catch( e => console.error(e));
    }
}

export function closeThread() {
    return dispatch => {
        return dispatch(destroyThread())
    }
}
import Axios from 'axios';
import {
    THREAD_REQUEST, 
    THREAD_LOADED, 
    THREAD_DESTROY,
    THREAD_POST_LOAD
} from '../constants';


function requestThread(threadID) {
	console.log("Action RequestThread wth ID:", threadID);
    return {
        type: THREAD_REQUEST,
        threadID
    }
}

function receiveThread(thread) {
    console.log("Action RecieveThread:", thread);
    return {
        type: THREAD_LOADED,
        payload: thread.data
    }
}

function destroyThread() {
    console.log('Action DestroyThread');
    return {
        type: THREAD_DESTROY
    }
}

export function fetchThread(threadID, provider="4chan", boardID="g") {
    console.log(`Action FetchThread() to /${provider}/${boardID}/${threadID}`);
    return dispatch => {
        dispatch(requestThread(threadID));
        return Axios.get(`/${provider}/${boardID}/${threadID}`)
            .then(data => dispatch(receiveThread(data)))
            .catch( e => console.error(e));
    }
}

export function closeThread() {
    return dispatch => {
        return dispatch(destroyThread())
    }
}
Remove debug logging in thread actions