-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsta-card.js
More file actions
200 lines (180 loc) · 6.74 KB
/
Copy pathinsta-card.js
File metadata and controls
200 lines (180 loc) · 6.74 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
* `insta-card`
* An Instagram-style photo card that loads a fox from an API.
*/
import { LitElement, html, css } from "lit";
import { DDDSuper } from "@haxtheweb/d-d-d/d-d-d.js";
import { I18NMixin } from "@haxtheweb/i18n-manager/lib/I18NMixin.js";
export class InstaCard extends DDDSuper(I18NMixin(LitElement)) {
static get tag() {
return "insta-card";
}
constructor() {
super();
this.image = "";
this.link = "";
this.liked = false;
this.likeCount = 0;
this.loading = true;
this.name = "";
this.description = "";
this.authorName = "";
this.authorImage = "";
this.authorSince = "";
this.channel = "";
}
static get properties() {
return {
...super.properties,
image: { type: String },
link: { type: String },
liked: { type: Boolean },
likeCount: { type: Number },
name: { type: String },
description: { type: String },
authorName: { type: String },
authorImage: { type: String },
authorSince: { type: String },
channel: { type: String },
};
}
static get styles() {
return [super.styles,
css`
:host {
display: block;
color-scheme: light dark;
}
.card {
background: light-dark(var(--ddd-theme-default-white), black);
//removed border might need to add back here
width: 100%;
max-width: 470px;
margin: 0px auto;
overflow: hidden;
}
.card-header {
display: flex;
align-items: center;
padding: var(--ddd-spacing-3) var(--ddd-spacing-4);
gap: var(--ddd-spacing-3);
}
.user-img {
width: 38px;
height: 38px;
border-radius: var(--ddd-radius-circle);
object-fit: cover;
}
.card-image img {
width: 100%;
aspect-ratio: 1 / 1;
object-fit: cover;
display: block;
}
.card-image {
width: 100%;
background: light-dark(var(--ddd-theme-default-white), var(--ddd-theme-default-coalyGray));
min-height: 300px;
display: flex;
align-items: center;
justify-content: center;
}
.heart-btn {
background: none;
border: none;
cursor: pointer;
font-size: var(--ddd-icon-md);
padding: var(--ddd-spacing-2) var(--ddd-spacing-4);
}
.heart-btn.liked {
color: red;
}
.like-count {
padding: 0 16px 8px;
font-weight: bold;
font-size: var(--ddd-font-size-4xs);
color: light-dark(black,var(--ddd-theme-default-white));
}
.share-btn {
background: light-dark(black,var(--ddd-theme-default-white));
border: none;
cursor: pointer;
font-size: var(--ddd-font-size-4xs);
padding: var(--ddd-spacing-2) var(--ddd-spacing-4);
margin-left: 375px;
color: light-dark(var(--ddd-theme-default-skyLight), var(--ddd-theme-default-beaverBlue));
margin-top: -40px;
}
.card-name {
padding: var(--ddd-spacing-0) var(--ddd-spacing-4) var(--ddd-spacing-1);
font-weight: bold;
font-size: var(--ddd-font-size-s);
}
.card-description {
padding: var(--ddd-spacing-0) var(--ddd-spacing-4) var(--ddd-spacing-3);
font-size: var(--ddd-font-size-xxs);
color: light-dark(var(--ddd-theme-default-coalyGray), var(--ddd-theme-default-limestoneGray));
height: var(--ddd-spacing-12);
overflow-y: auto;
}
.card-description::-webkit-scrollbar {
width: 12px;
}
.card-description::-webkit-scrollbar-track {
background: var(--ddd-theme-default-limestoneLight);
}
.card-description::-webkit-scrollbar-thumb {
background-color: var(--ddd-theme-default-beaverBlue);
border-radius: var(--ddd-radius-rounded);
border: 3px var(--ddd-theme-default-beaverBlue);
}
`];
}
_toggleLike() {
this.liked = !this.liked;
this.likeCount = this.liked ? this.likeCount + 1 : this.likeCount - 1;
localStorage.setItem(`liked-${this.name}`, JSON.stringify(this.liked));
localStorage.setItem(`likeCount-${this.name}`, JSON.stringify(this.likeCount));
}
_sharePhoto() {
navigator.clipboard.writeText(window.location.href);
alert("Link copied to clipboard!");
}
updated(changedProperties) {
if (changedProperties.has("name") && this.name) {
const savedLiked = localStorage.getItem(`liked-${this.name}`);
const savedCount = localStorage.getItem(`likeCount-${this.name}`);
this.liked = savedLiked ? JSON.parse(savedLiked) : false;
this.likeCount = savedCount ? JSON.parse(savedCount) : 0;
}
}
render() {
return html`
<div class="card">
<div class="card-header">
<img class="user-img" src="${this.authorImage}" alt="user profile pic" />
<div>
<div>${this.authorName}</div>
<div>@${this.channel} - since ${this.authorSince}</div>
</div>
</div>
<div class="card-image">
${this.image
? html`<img src="${this.image}" alt="${this.name}" loading="lazy"/>`
: html`<span>Loading...</span>`
}
</div>
<button
class="heart-btn ${this.liked ? 'liked' : ''}"
@click="${this._toggleLike}">
${this.liked ? '\u2665' : '\u2665'}
</button>
<div class="like-count">${this.likeCount} likes</div>
<button class="share-btn" @click="${this._sharePhoto}">Share</button>
<div class="card-name">${this.name}</div>
<div class="card-description">${this.description}</div>
</div>
`;
}
}
globalThis.customElements.define(InstaCard.tag, InstaCard);