1// Copyright (C) 2020 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import m from 'mithril'; 16import {AppImpl} from './app_impl'; 17 18const COOKIE_ACK_KEY = 'cookieAck'; 19 20export class CookieConsent implements m.ClassComponent { 21 private showCookieConsent = true; 22 23 oninit() { 24 this.showCookieConsent = true; 25 if ( 26 !AppImpl.instance.analytics.isEnabled() || 27 localStorage.getItem(COOKIE_ACK_KEY) === 'true' 28 ) { 29 this.showCookieConsent = false; 30 } 31 } 32 33 view() { 34 if (!this.showCookieConsent) return; 35 return m( 36 '.cookie-consent', 37 m( 38 '.cookie-text', 39 `This site uses cookies from Google to deliver its services and to 40 analyze traffic.`, 41 ), 42 m( 43 '.buttons', 44 m( 45 'button', 46 m( 47 'a', 48 { 49 href: 'https://policies.google.com/technologies/cookies', 50 target: '_blank', 51 }, 52 'More details', 53 ), 54 ), 55 m( 56 'button', 57 { 58 onclick: () => { 59 this.showCookieConsent = false; 60 localStorage.setItem(COOKIE_ACK_KEY, 'true'); 61 }, 62 }, 63 'OK', 64 ), 65 ), 66 ); 67 } 68} 69