summaryrefslogtreecommitdiffstats
path: root/browser/components/pocket/content/panels/js/home/overlay.js
blob: 89c881ecee6f9b82fa5642c311fe51cb9ccad047 (plain)
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
/* global Handlebars:false */

/*
HomeOverlay is the view itself and contains all of the methods to manipute the overlay and messaging.
It does not contain any logic for saving or communication with the extension or server.
*/

import React from "react";
import ReactDOM from "react-dom";
import Home from "../components/Home/Home";

var HomeOverlay = function (options) {
  this.inited = false;
  this.active = false;
};

HomeOverlay.prototype = {
  create({ pockethost }) {
    const { searchParams } = new URL(window.location.href);
    const locale = searchParams.get(`locale`) || ``;
    const hideRecentSaves = searchParams.get(`hiderecentsaves`) === `true`;
    const utmSource = searchParams.get(`utmSource`);
    const utmCampaign = searchParams.get(`utmCampaign`);
    const utmContent = searchParams.get(`utmContent`);

    if (this.active) {
      return;
    }

    this.active = true;

    ReactDOM.render(
      <Home
        locale={locale}
        hideRecentSaves={hideRecentSaves}
        pockethost={pockethost}
        utmSource={utmSource}
        utmCampaign={utmCampaign}
        utmContent={utmContent}
        topics={[
          { title: "Technology", topic: "technology" },
          { title: "Self Improvement", topic: "self-improvement" },
          { title: "Food", topic: "food" },
          { title: "Parenting", topic: "parenting" },
          { title: "Science", topic: "science" },
          { title: "Entertainment", topic: "entertainment" },
          { title: "Career", topic: "career" },
          { title: "Health", topic: "health" },
          { title: "Travel", topic: "travel" },
          { title: "Must-Reads", topic: "must-reads" },
        ]}
      />,
      document.querySelector(`body`)
    );

    if (window?.matchMedia(`(prefers-color-scheme: dark)`).matches) {
      document.querySelector(`body`).classList.add(`theme_dark`);
    }
  },
};

export default HomeOverlay;