All files / src/components/Content index.tsx

85.71% Statements 12/14
75% Branches 3/4
80% Functions 4/5
85.71% Lines 12/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71                          4x 4x 4x           4x   4x       2x 2x     1x       2x           4x         4x 4x                                              
import React, { Component } from "react";
import lozad from "lozad";
 
import { isBrowser } from "@/utils";
import * as style from "./index.module.scss";
 
type Props = {
  post: string;
};
 
class Content extends Component<Props> {
  private post: string;
  constructor(props: Props) {
    super(props);
    const { post } = this.props;
    this.post = post;
  }
 
  componentDidMount() {
    // lazy loads elements with default selector as '.lozad'
    // Prevent WebPack build fail
    Eif (isBrowser()) {
      // Initialize library
      const observer = lozad(".lozad", {
        load(el) {
          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
          // @ts-ignore
          el.src = el.dataset.src;
          if (el.getAttribute("data-background-image")) {
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
            // @ts-ignore
            el.style.backgroundImage = el.getAttribute("data-background-image");
          }
          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
          // @ts-ignore
          el.onload = () => {
            el.classList.add("animated");
            el.classList.add("fadeIn");
          };
        },
      });
      observer.observe();
    }
  }
 
  render() {
    const { post } = this.props;
    return (
      <>
        <div
          className={style.contentWhiteInner}
          data-testid="innerHTML"
          dangerouslySetInnerHTML={{ __html: post }}
        />
        <div className={style.contentWhiteInner}>
          <h2>tubone24にラーメンを食べさせよう!</h2>
          <p>ぽちっとな↓</p>
          <a href="https://www.buymeacoffee.com/tubone24">
            <img
              src="https://img.buymeacoffee.com/button-api/?text=Buy me a ramen&emoji=🍜&slug=tubone24&button_colour=40DCA5&font_colour=ffffff&font_family=Lato&outline_colour=000000&coffee_colour=FFDD00"
              alt="Buy me a ramen"
            />
          </a>
        </div>
      </>
    );
  }
}
 
export default Content;