Skip to content

Commit 5875bd2

Browse files
authored
Merge pull request #204 from joyofrails/feat/screenshot-dimensions
Update snippet screenshot dimensions
2 parents b078e19 + 870109e commit 5875bd2

File tree

36 files changed

+182
-89
lines changed

36 files changed

+182
-89
lines changed

app/content/layouts/article.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</nav>
3434
</aside>
3535
<%- end -%>
36-
<div class="article-content container" itemprop="articleBody">
36+
<div class="article-content container mb-3xl" itemprop="articleBody">
3737
<%= yield %>
3838
</div>
3939
</article>

app/controllers/share/snippet_screenshots_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ def show
99

1010
def new
1111
@snippet = Snippet.find(params[:snippet_id])
12+
@auto = params[:auto] == "true"
1213
end
1314

1415
def create
1516
@snippet = Snippet.find(params[:snippet_id])
1617
@snippet.attach_screenshot_from_base64(params[:screenshot])
17-
redirect_to new_share_snippet_tweet_path(@snippet, auto: true), notice: "Screenshot attached".emojoy
18+
redirect_to new_share_snippet_tweet_path(@snippet, auto: true), notice: "Screenshot successful".emojoy
1819
end
1920
end

app/controllers/share/snippets_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ def destroy
6666

6767
def share_snippet_redirect_url(snippet)
6868
case params[:commit]
69-
when "Share"
70-
new_share_snippet_screenshot_url(snippet)
69+
when /Close/
70+
share_snippet_url(snippet)
71+
when /Share/
72+
new_share_snippet_screenshot_url(snippet, auto: true)
7173
else
7274
edit_share_snippet_url(snippet)
7375
end

app/javascript/controllers/snippets/screenshot.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ import debug from '../../utils/debug';
66
const console = debug('app:javascript:controllers:snippets:screenshot');
77

88
export default class extends Controller<HTMLFormElement> {
9+
static values = {
10+
auto: Boolean,
11+
};
12+
913
static targets = ['snippet', 'submitButton'];
1014

1115
declare readonly snippetTarget: HTMLInputElement;
1216
declare readonly submitButtonTarget: HTMLInputElement;
17+
declare readonly autoValue: boolean;
1318

1419
connect(): void {
1520
console.log('Connect!');
@@ -19,9 +24,11 @@ export default class extends Controller<HTMLFormElement> {
1924
this.prepareScreenshot,
2025
);
2126

22-
// submit immediately
23-
this.submitButtonTarget.click();
24-
this.submitButtonTarget.disabled = true;
27+
if (this.autoValue) {
28+
// submit immediately
29+
this.submitButtonTarget.click();
30+
this.submitButtonTarget.disabled = true;
31+
}
2532
}
2633

2734
prepareScreenshot = async (event) => {

app/javascript/controllers/snippets/tweet.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1+
import { Turbo } from '@hotwired/turbo-rails';
12
import { Controller } from '@hotwired/stimulus';
23

34
import debug from '../../utils/debug';
45

56
const console = debug('app:javascript:controllers:snippets:tweet');
67

8+
const WINDOW_OPTIONS = {
9+
width: 550,
10+
height: 420,
11+
toolbar: false,
12+
location: false,
13+
directories: false,
14+
status: false,
15+
menubar: false,
16+
scrollbars: true,
17+
copyhistory: false,
18+
resizable: true,
19+
};
20+
21+
const WINDOW_OPTIONS_ARGUMENT = Object.entries(WINDOW_OPTIONS)
22+
.map(([key, value]) => `${key}=${value}`)
23+
.join(',');
724
export default class extends Controller {
825
static values = {
926
url: String,
@@ -18,6 +35,7 @@ export default class extends Controller {
1835

1936
if (this.autoValue) {
2037
this.tweet();
38+
Turbo.visit(this.urlValue);
2139
}
2240
}
2341

@@ -30,10 +48,6 @@ export default class extends Controller {
3048

3149
const tweetUrl = `https://x.com/intent/post?text=${tweetText}`;
3250

33-
window.open(
34-
tweetUrl,
35-
'_blank',
36-
'width=550,height=420,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes',
37-
);
51+
window.open(tweetUrl, '_blank', WINDOW_OPTIONS_ARGUMENT);
3852
}
3953
}

app/javascript/css/components/article-content.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
.article-content,
22
.section-content {
3-
padding-bottom: var(--space-3xl);
4-
53
& h1,
64
& h2,
75
& h3,

app/javascript/css/components/code.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
--code-line-height: 1.7777778;
55

66
border-radius: var(--space-3xs-2xs);
7-
border: 1px solid var(--joy-border-quiet);
87

98
& input,
109
& textarea {

app/javascript/css/components/snippet.css

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
11
.snippet {
2-
filter: drop-shadow(0 0 0.75rem var(--joy-color-50));
2+
filter: drop-shadow(0.25rem 0.5rem 0.75rem var(--joy-color-500));
33
width: fit-content;
4-
max-width: var(--grid-max-width);
4+
max-width: var(--grid-max-width) - (2 * var(--grid-gutter));
55

66
& .code-editor {
77
padding-top: var(--space-xs);
88
padding-inline-end: var(--space-m);
99
padding-bottom: var(--space-m);
1010
padding-inline-start: var(--space-m);
1111
}
12+
13+
& .clipboard-copy-container {
14+
position: absolute;
15+
right: 0px;
16+
display: none;
17+
}
18+
19+
&:hover .clipboard-copy-container {
20+
display: block;
21+
}
1222
}
1323

1424
.snippet-background {
15-
background-color: var(--joy-color-200);
25+
background: linear-gradient(var(--joy-color-300), var(--joy-color-200));
1626
padding: var(--space-l);
1727
width: fit-content;
28+
aspect-ratio: 2 / 1;
1829
border-radius: 0.5rem;
30+
max-width: var(--grid-max-width);
31+
overflow-x: clip;
32+
33+
display: flex;
34+
flex-direction: column;
35+
justify-content: center;
36+
37+
& .code-wrapper {
38+
margin: 0 auto;
39+
}
1940
}
2041

2142
/*

app/javascript/css/utilities/custom.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
margin-bottom: var(--grid-gutter);
33
}
44

5-
.mb-gap {
6-
margin-bottom: var(--grid-gutter);
5+
.mb-xl {
6+
margin-bottom: var(--space-xl);
7+
}
8+
9+
.mb-3xl {
10+
margin-bottom: var(--space-3xl);
711
}
812

913
.py-gap {

app/views/admin/newsletters/edit.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%= render Pages::Header.new(title: "Newsletter: Edit") %>
2-
<div class="section-content container py-gap">
2+
<div class="section-content container py-gap mb-3xl">
33
<%= render "form", newsletter: @newsletter %>
44

55
<div>

0 commit comments

Comments
 (0)