|
| 1 | +import { html, msg, router, store } from 'hybrids'; |
| 2 | + |
| 3 | +import * as labels from '@ghostery/ui/labels'; |
| 4 | + |
| 5 | +import { isCategoryBlockedByDefault } from '/utils/trackerdb.js'; |
| 6 | + |
| 7 | +import TabStats from '/store/tab-stats.js'; |
| 8 | +import TrackerException from '/store/tracker-exception.js'; |
| 9 | + |
| 10 | +function toggleException(type) { |
| 11 | + return ({ exception, stats }) => { |
| 12 | + const list = [...exception[type]]; |
| 13 | + const index = list.indexOf(stats.domain); |
| 14 | + if (index !== -1) { |
| 15 | + list.splice(index, 1); |
| 16 | + } else { |
| 17 | + list.push(stats.domain); |
| 18 | + } |
| 19 | + |
| 20 | + store.set(exception, { [type]: list }); |
| 21 | + }; |
| 22 | +} |
| 23 | + |
| 24 | +export default { |
| 25 | + [router.connect]: { dialog: true }, |
| 26 | + stats: store(TabStats), |
| 27 | + trackerId: '', |
| 28 | + tracker: ({ stats, trackerId }) => |
| 29 | + stats.trackers.find((t) => t.id === trackerId), |
| 30 | + exception: store(TrackerException, { id: 'trackerId' }), |
| 31 | + blockedByDefault: ({ tracker }) => |
| 32 | + isCategoryBlockedByDefault(tracker.category), |
| 33 | + blockedOnSite: ({ stats, exception }) => |
| 34 | + store.ready(exception) && exception.blocked.includes(stats.domain), |
| 35 | + allowedOnSite: ({ stats, exception }) => |
| 36 | + store.ready(exception) && exception.allowed.includes(stats.domain), |
| 37 | + content: ({ |
| 38 | + stats, |
| 39 | + tracker, |
| 40 | + exception, |
| 41 | + blockedByDefault, |
| 42 | + blockedOnSite, |
| 43 | + allowedOnSite, |
| 44 | + }) => html` |
| 45 | + <template layout="column"> |
| 46 | + <gh-panel-dialog> |
| 47 | + <div |
| 48 | + id="gh-panel-company-alerts" |
| 49 | + layout="absolute inset:1 bottom:auto" |
| 50 | + ></div> |
| 51 | + <ui-text slot="header" type="label-l">${tracker.name}</ui-text> |
| 52 | +
|
| 53 | + ${tracker.company !== tracker.name && |
| 54 | + html` |
| 55 | + <ui-text slot="header" type="body-s" color="gray-600"> |
| 56 | + ${tracker.company} • ${labels.categories[tracker.category]} |
| 57 | + </ui-text> |
| 58 | + `} |
| 59 | + ${store.ready(exception) && |
| 60 | + html` |
| 61 | + <div layout="column gap"> |
| 62 | + <div layout="row:wrap gap"> |
| 63 | + <div layout="grow"> |
| 64 | + <ui-text type="label-m">Protection status</ui-text> |
| 65 | + <ui-text type="body-s" color="gray-500"> |
| 66 | + For all websites |
| 67 | + </ui-text> |
| 68 | + </div> |
| 69 | + <ui-panel-protection-status-toggle |
| 70 | + layout="shrink:0" |
| 71 | + value="${exception.overwriteStatus}" |
| 72 | + blockByDefault="${blockedByDefault}" |
| 73 | + tooltip |
| 74 | + onchange="${html.set(exception, 'overwriteStatus')}" |
| 75 | + ></ui-panel-protection-status-toggle> |
| 76 | + </div> |
| 77 | + <ui-line></ui-line> |
| 78 | + <div layout="row gap items:center"> |
| 79 | + <div layout="grow"> |
| 80 | + <ui-text type="label-m"> |
| 81 | + Add ${stats.domain} as exception |
| 82 | + </ui-text> |
| 83 | + <ui-text type="body-m" color="gray-500"> |
| 84 | + ${blockedByDefault === exception.overwriteStatus |
| 85 | + ? msg`Block on this website` |
| 86 | + : msg`Trust on this website`} |
| 87 | + </ui-text> |
| 88 | + </div> |
| 89 | + ${blockedByDefault === exception.overwriteStatus |
| 90 | + ? html` |
| 91 | + <ui-toggle |
| 92 | + value="${blockedOnSite}" |
| 93 | + onchange="${toggleException('blocked')}" |
| 94 | + type="status" |
| 95 | + color="danger-500" |
| 96 | + ></ui-toggle> |
| 97 | + ` |
| 98 | + : html` |
| 99 | + <ui-toggle |
| 100 | + value="${allowedOnSite}" |
| 101 | + onchange="${toggleException('allowed')}" |
| 102 | + type="status" |
| 103 | + color="success-500" |
| 104 | + ></ui-toggle> |
| 105 | + `} |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + `} |
| 109 | + </gh-panel-dialog> |
| 110 | + </template> |
| 111 | + `, |
| 112 | +}; |
0 commit comments