Sha256: e6c14d8c48af6b412a1a40eb8e8ada827320e163e0039d6e64bbd1109885d2dd

Contents?: true

Size: 851 Bytes

Versions: 24

Compression:

Stored size: 851 Bytes

Contents

import Cookies from "js-cookie";
import {
  parseSearchParamValue,
  buildSearchParamValue,
} from "~/app/assets/lookbook/js/helpers/string";

export default function displayOptionsFieldComponent({ name, value }) {
  return {
    name,
    value,

    init() {
      this.$watch("value", () => this.update());
    },

    update() {
      Cookies.set(`lookbook-display-${name}`, this.value);

      const searchParams = new URLSearchParams(window.location.search);
      const display = searchParams.get("_display");

      const displayParams = display ? parseSearchParamValue(display) : {};
      displayParams[this.name] = this.value;
      searchParams.set("_display", buildSearchParamValue(displayParams));

      const path = location.href.replace(location.search, "");
      this.navigateTo(`${path}?${searchParams.toString()}`);
    },
  };
}

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
lookbook-1.3.1 app/components/lookbook/display_options/field/component.js
lookbook-1.3.0 app/components/lookbook/display_options/field/component.js
lookbook-1.2.1 app/components/lookbook/display_options/field/component.js
lookbook-1.2.0 app/components/lookbook/display_options/field/component.js