Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 0be2fc8

Browse files
feat: publish use component card too
1 parent f562fb0 commit 0be2fc8

File tree

7 files changed

+169
-244
lines changed

7 files changed

+169
-244
lines changed

studio/src/app/components/feed/card/app-feed-card-content/app-feed-card-content.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@ app-feed-card-content {
6464
text-overflow: ellipsis;
6565
}
6666
}
67+
68+
input {
69+
font-size: var(--font-size-normal);
70+
71+
pointer-events: visible;
72+
73+
background: transparent;
74+
color: var(--ion-color-primary);
75+
border: none;
76+
outline: 0;
77+
78+
padding-bottom: 1px;
79+
80+
max-width: 130px;
81+
height: 40px;
82+
83+
&::placeholder {
84+
color: var(--deckgo-inline-editor-link-placeholder-color, #3880ff);
85+
}
86+
}
6787
}
6888

6989
@media screen and (max-width: 720px) {

studio/src/app/components/feed/card/app-feed-card-content/app-feed-card-content.tsx

Lines changed: 117 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import {Component, Prop} from '@stencil/core';
1+
import {Component, Prop, State, Watch} from '@stencil/core';
2+
3+
import DateTimeFormatOptions = Intl.DateTimeFormatOptions;
4+
5+
interface InputTargetEvent extends EventTarget {
6+
value: string;
7+
}
28

39
@Component({
410
tag: 'app-feed-card-content',
@@ -7,30 +13,97 @@ import {Component, Prop} from '@stencil/core';
713
})
814
export class AppFeedCardContent {
915

16+
@State()
17+
private tags: string[] = [];
18+
19+
@State()
20+
private tagInput: string = null;
21+
1022
@Prop()
1123
firstCard: boolean = false;
1224

25+
@Prop()
26+
editable: boolean = false;
27+
28+
@Prop()
29+
author: string;
30+
31+
@Prop()
32+
publication: Date;
33+
34+
@State()
35+
private formattedPublication: string;
36+
37+
async componentWillLoad() {
38+
await this.formatPublication();
39+
}
40+
41+
@Watch('publication')
42+
formatPublication(): Promise<void> {
43+
return new Promise<void>((resolve) => {
44+
const options: DateTimeFormatOptions = {year: 'numeric', month: 'short', day: 'numeric'};
45+
this.formattedPublication = new Intl.DateTimeFormat('en-US', options).format(new Date());
46+
47+
resolve();
48+
});
49+
}
50+
51+
private handleTagInput($event: UIEvent) {
52+
const tag: string = ($event.target as InputTargetEvent).value;
53+
54+
if (tag && tag.trim().length > 0 && tag.charAt(tag.length - 1) === ' ' && this.tags && this.tags.indexOf(tag.trim()) === -1) {
55+
this.tags = [...this.tags, tag.trim()];
56+
this.tagInput = null;
57+
}
58+
}
59+
60+
private removeTag(tag: string): Promise<void> {
61+
return new Promise<void>((resolve) => {
62+
if (!tag) {
63+
resolve();
64+
return;
65+
}
66+
67+
if (!this.tags) {
68+
resolve();
69+
return;
70+
}
71+
72+
const index: number = this.tags.findIndex((actualTag: string) => {
73+
return tag === actualTag
74+
});
75+
76+
if (index >= 0) {
77+
this.tags.splice(index, 1);
78+
this.tags = [...this.tags];
79+
}
80+
81+
resolve();
82+
});
83+
}
84+
1385
render() {
1486
return <ion-card-content>
1587
<div class="summary">
1688

1789
<ion-card-header>
18-
<ion-card-title class="ion-text-uppercase">Card Title</ion-card-title>
90+
<ion-card-title class="ion-text-uppercase" contentEditable={this.editable}>Card Title
91+
</ion-card-title>
1992

2093
<ion-card-subtitle class="ion-text-lowercase">
21-
<div class="chips"><ion-label>Javascript&nbsp;</ion-label></div>
22-
<div class="chips"><ion-label>Typescript&nbsp;</ion-label></div>
23-
<div class="chips"><ion-label>Ionic&nbsp;</ion-label></div>
94+
{this.renderTags()}
95+
{this.renderInputTags()}
2496
</ion-card-subtitle>
2597
</ion-card-header>
2698

27-
<p padding-start padding-end class="content ion-text-lowercase">Keep close to Nature's heart... and break clear away, once in
99+
<p padding-start padding-end class="content ion-text-lowercase" contentEditable={this.editable}>Keep
100+
close to Nature's heart... and break clear away, once in
28101
awhile,
29102
and climb a mountain or spend a week in the woods. Wash your spirit clean.
30103
</p>
31104

32105
<p class="author" padding>
33-
<ion-label>David Dal Busco | Mars 9</ion-label>
106+
<ion-label>{this.author} | {this.formattedPublication}</ion-label>
34107
</p>
35108
</div>
36109

@@ -48,4 +121,41 @@ export class AppFeedCardContent {
48121
}
49122
}
50123

124+
private renderTags() {
125+
if (!this.tags || this.tags.length <= 0) {
126+
return undefined;
127+
} else {
128+
return (
129+
this.tags.map((tag: string) => {
130+
return (
131+
<div class="chips">
132+
{this.renderCloseTags(tag)}
133+
<ion-label>{tag}</ion-label>
134+
</div>
135+
)
136+
})
137+
);
138+
}
139+
}
140+
141+
private renderCloseTags(tag: string) {
142+
if (!this.editable) {
143+
return undefined;
144+
} else {
145+
<ion-icon name="close" custom-tappable onClick={() => this.removeTag(tag)}></ion-icon>
146+
}
147+
}
148+
149+
private renderInputTags() {
150+
if (!this.editable) {
151+
return undefined;
152+
}
153+
154+
if (this.tags && this.tags.length < 5) {
155+
return <input autofocus placeholder="Add a tag..." value={this.tagInput}
156+
onInput={($event: UIEvent) => this.handleTagInput($event)}></input>
157+
} else {
158+
return undefined;
159+
}
160+
}
51161
}

studio/src/app/components/feed/card/app-feed-card/app-feed-card.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component} from '@stencil/core';
1+
import {Component, Prop} from '@stencil/core';
22

33
@Component({
44
tag: 'app-feed-card',
@@ -7,10 +7,19 @@ import {Component} from '@stencil/core';
77
})
88
export class AppFeedCard {
99

10+
@Prop()
11+
editable: boolean = false;
12+
13+
@Prop()
14+
author: string;
15+
16+
@Prop()
17+
publication: Date;
18+
1019
render() {
1120

12-
return <ion-card>
13-
<app-feed-card-content></app-feed-card-content>
21+
return <ion-card class={this.editable ? "ion-no-margin" : undefined}>
22+
<app-feed-card-content editable={this.editable} author={this.author} publication={this.publication}></app-feed-card-content>
1423
</ion-card>
1524
}
1625

studio/src/app/modals/editor/app-publish/app-publish.scss

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,4 @@ app-publish {
22
ion-content {
33
--background: var(--ion-color-light);
44
}
5-
6-
@import "../../../../global/theme/feed/feed-card";
7-
8-
ion-card-subtitle.tags {
9-
background: white;
10-
11-
@media only screen and (min-height: 600px) and (min-width: 768px) {
12-
flex-wrap: inherit;
13-
}
14-
15-
min-height: 42px;
16-
}
17-
18-
input {
19-
font-size: var(--font-size-normal);
20-
}
21-
22-
input {
23-
pointer-events: visible;
24-
25-
background: transparent;
26-
color: var(--ion-color-primary);
27-
border: none;
28-
outline: 0;
29-
30-
padding-bottom: 1px;
31-
32-
max-width: 130px;
33-
height: 40px;
34-
35-
&::placeholder {
36-
color: var(--deckgo-inline-editor-link-placeholder-color, #3880ff);
37-
}
38-
}
395
}

0 commit comments

Comments
 (0)