<commit_before>import * as React from "react";
import { BaseContainer } from "../../../BaseContainer";
import classnames from "classnames";
import { SubscriptionContentsState } from "./SubscriptionContentsStore";
import {
    SubscriptionContent,
    SubscriptionContentIdentifier
} from "../../../../../domain/Subscriptions/SubscriptionContent/SubscriptionContent";
import { DefaultButton, Image, ImageFit, Link, Toggle } from "office-ui-fabric-react";
import { FocusContentUseCase } from "./use-case/FocusContentUseCase";
import { ProgressColorBar } from "../../../../project/ProgressColorBar/ProgressColorBar";
import { Subscription } from "../../../../../domain/Subscriptions/Subscription";
import { Time } from "../../../../ui-kit/Time/Time";
import { TurnOffContentsFilterUseCase, TurnOnContentsFilterUseCase } from "./use-case/ToggleFilterContents";
import { createFetchMoreSubscriptContentsUseCase } from "../../../../../use-case/subscription/FetchMoreSubscriptContentsUseCase";
import { SubscriptionContentComponent } from "./SubscriptionContent/SubscriptionContentComponent";

const format = require("date-fns/format");

export interface SubscriptionContentsContainerProps {
    subscriptionContents: SubscriptionContentsState;
}

/**
 * get Active Item from the scroll position
 * @see https://gist.github.com/azu/c306c1efa31f0f41aa01c5b69576d00c#file-reader_main-0-3-8-js-L1205
 * @returns {string}
 */
export function getActiveContentIdString(): string | undefined {
    const contentContainer = document.querySelector(".SubscriptionContentsContainer") as HTMLElement;
    const contentElements = document.querySelectorAll(".SubscriptionContentsContainer-content") as NodeListOf<
        HTMLElement
    >;
    const containerScrollTop = contentContainer.scrollTop;
    const containerOffsetHeight = contentContainer.offsetHeight;
    // TODO: should be computable
    // AppHeader's height = 32px
    const marginTopOfContentContainer = 32;
    const contentCount = contentElements.length;
    if (!contentCount) {
        return;
    }
    const offsets: number[] = [];
    for (let i = 0; i < contentCount; i++) {
        offsets.push(contentElements[i].offsetTop - marginTopOfContentContainer);
    }
    if (!contentContainer) {
        return;
    }
    const screen = [containerScrollTop, containerScrollTop + containerOffsetHeight];
    const pairs = offsets.map(function(v, i, element) {
        if (element[i + 1]) {
            return [v, element[i + 1]];
        } else {
            return [v, containerOffsetHeight];
        }
    });
    const full_contain: number[] = [];
    const intersections = pairs.map(function(pair, i) {
        if (pair[1] < screen[0]) {
            return 0;
        }
        if (pair[0] > screen[1]) {
            return 0;
        }
        const top = Math.max(screen[0], pair[0]);
        const bottom = Math.min(screen[1], pair[1]);
        if (top == pair[0] && bottom == pair[1]) {
            full_contain.push(i);
        }
        return bottom - top;
    });
    if (contentCount == 1) {
        const content = contentElements[0];
        return content.dataset.contentId;
    } else {
        if (full_contain.length > 0) {
            const offset = full_contain.shift();<commit_msg>chore: add debug log<commit_after>import * as React from "react";
import { BaseContainer } from "../../../BaseContainer";
import classnames from "classnames";
import { SubscriptionContentsState } from "./SubscriptionContentsStore";
import {
    SubscriptionContent,
    SubscriptionContentIdentifier
} from "../../../../../domain/Subscriptions/SubscriptionContent/SubscriptionContent";
import { DefaultButton, Image, ImageFit, Link, Toggle } from "office-ui-fabric-react";
import { FocusContentUseCase } from "./use-case/FocusContentUseCase";
import { ProgressColorBar } from "../../../../project/ProgressColorBar/ProgressColorBar";
import { Subscription } from "../../../../../domain/Subscriptions/Subscription";
import { Time } from "../../../../ui-kit/Time/Time";
import { TurnOffContentsFilterUseCase, TurnOnContentsFilterUseCase } from "./use-case/ToggleFilterContents";
import { createFetchMoreSubscriptContentsUseCase } from "../../../../../use-case/subscription/FetchMoreSubscriptContentsUseCase";
import { SubscriptionContentComponent } from "./SubscriptionContent/SubscriptionContentComponent";
const debug = require("debug")("irodr:SubscriptionContentsContainer");
const format = require("date-fns/format");

export interface SubscriptionContentsContainerProps {
    subscriptionContents: SubscriptionContentsState;
}

/**
 * get Active Item from the scroll position
 * @see https://gist.github.com/azu/c306c1efa31f0f41aa01c5b69576d00c#file-reader_main-0-3-8-js-L1205
 * @returns {string}
 */
export function getActiveContentIdString(): string | undefined {
    const contentContainer = document.querySelector(".SubscriptionContentsContainer") as HTMLElement;
    const contentElements = document.querySelectorAll(".SubscriptionContentsContainer-content") as NodeListOf<
        HTMLElement
    >;
    const containerScrollTop = contentContainer.scrollTop;
    const containerOffsetHeight = contentContainer.offsetHeight;
    // TODO: should be computable
    // AppHeader's height = 32px
    const marginTopOfContentContainer = 32;
    const contentCount = contentElements.length;
    if (!contentCount) {
        return;
    }
    const offsets: number[] = [];
    for (let i = 0; i < contentCount; i++) {
        offsets.push(contentElements[i].offsetTop - marginTopOfContentContainer);
    }
    if (!contentContainer) {
        return;
    }
    const screen = [containerScrollTop, containerScrollTop + containerOffsetHeight];
    const pairs = offsets.map(function(v, i, element) {
        if (element[i + 1]) {
            return [v, element[i + 1]];
        } else {
            return [v, containerOffsetHeight];
        }
    });
    const full_contain: number[] = [];
    debug("getActiveContentIdString:pairs", pairs);
    const intersections = pairs.map(function(pair, i) {
        if (pair[1] < screen[0]) {
            return 0;
        }
        if (pair[0] > screen[1]) {
            return 0;
        }
        const top = Math.max(screen[0], pair[0]);
        const bottom = Math.min(screen[1], pair[1]);
        if (top == pair[0] && bottom == pair[1]) {
            full_contain.push(i);
        }
        return bottom - top;
    });
    debug("getActiveContentIdString:full_contain", full_contain);
    debug("getActiveContentIdString:intersections", intersections);
    if (contentCount == 1) {
        const content = contentElements[0];
        return content.dataset.contentId;
    } else {
        if (full_contain.length > 0) {
            const offset = full_contain.shift();
{'fraction_non_alphanumeric': 0.1328113458413355, 'fraction_numerical': 0.014182301669375093, 'mean_word_length': 3.2766898294377764, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '539157', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1839, 'n_words': 413}