Skip to content

Commit

Permalink
Update new page
Browse files Browse the repository at this point in the history
  • Loading branch information
hschne committed Dec 23, 2023
1 parent 941d6e1 commit 2153163
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 94 deletions.
1 change: 1 addition & 0 deletions app/assets/images/file.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/images/upload.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 0 additions & 10 deletions app/assets/stylesheets/application.tailwind.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

/*
@layer components {
.btn-primary {
@apply py-2 px-4 bg-blue-200;
}
}
*/
19 changes: 19 additions & 0 deletions app/javascript/controllers/clipboard_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
static targets = ["source"];

copy(event) {
event.preventDefault();
navigator.clipboard.writeText(this.sourceTarget.value);

this.sourceTarget.focus();
var triggerElement = this.triggerTarget;
var initialHTML = triggerElement.innerHTML;
triggerElement.innerHTML = "<span style='color:grey;'>Copied</span>";
setTimeout(() => {
triggerElement.innerHTML = initialHTML;
this.sourceTarget.blur();
}, 2000);
}
}
15 changes: 15 additions & 0 deletions app/javascript/controllers/drop_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
static targets = ["text", "uploadIcon", "fileIcon"];

display(event) {
const file = event.target.files[0];
if (file) {
const fileName = file.name;
this.textTarget.innerHTML = `${fileName}`;
this.uploadIconTarget.classList.toggle("hidden");
this.fileIconTarget.classList.toggle("hidden");
}
}
}
7 changes: 0 additions & 7 deletions app/javascript/controllers/hello_controller.js

This file was deleted.

101 changes: 101 additions & 0 deletions app/javascript/controllers/tabs_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
static classes = ["activeTab", "inactiveTab"];
static targets = ["tab", "panel", "select"];
static values = {
index: 0,
updateAnchor: Boolean,
};

connect() {
if (this.anchor)
this.indexValue = this.tabTargets.findIndex(
(tab) => tab.id === this.anchor,
);
this.showTab();
}

// Changes to the clicked tab
change(event) {
if (event.currentTarget.tagName === "SELECT") {
this.indexValue = event.currentTarget.selectedIndex;

// If target specifies an index, use that
} else if (event.currentTarget.dataset.index) {
this.indexValue = event.currentTarget.dataset.index;

// If target specifies an id, use that
} else if (event.currentTarget.dataset.id) {
this.indexValue = this.tabTargets.findIndex(
(tab) => tab.id == event.currentTarget.dataset.id,
);

// Otherwise, use the index of the current target
} else {
this.indexValue = this.tabTargets.indexOf(event.currentTarget);
}
event.stopPropagation();
window.dispatchEvent(new CustomEvent("tsc:tab-change"));
}

nextTab() {
this.indexValue = Math.min(this.indexValue + 1, this.tabsCount - 1);
}

previousTab() {
this.indexValue = Math.max(this.indexValue - 1, 0);
}

firstTab() {
this.indexValue = 0;
}

lastTab() {
this.indexValue = this.tabsCount - 1;
}

indexValueChanged() {
this.showTab();

// Update URL with the tab ID if it has one
// This will be automatically selected on page load
if (this.updateAnchorValue) {
location.hash = this.tabTargets[this.indexValue].id;
}
}

showTab() {
this.panelTargets.forEach((panel, index) => {
const tab = this.tabTargets[index];

if (index === this.indexValue) {
panel.classList.remove("hidden");
if (this.hasInactiveTabClass)
tab?.classList?.remove(...this.inactiveTabClasses);
if (this.hasActiveTabClass)
tab?.classList?.add(...this.activeTabClasses);
} else {
panel.classList.add("hidden");
if (this.hasActiveTabClass)
tab?.classList?.remove(...this.activeTabClasses);
if (this.hasInactiveTabClass)
tab?.classList?.add(...this.inactiveTabClasses);
}
});

if (this.hasSelectTarget) {
this.selectTarget.selectedIndex = this.indexValue;
}
}

get tabsCount() {
return this.tabTargets.length;
}

get anchor() {
return document.URL.split("#").length > 1
? document.URL.split("#")[1]
: null;
}
}
79 changes: 56 additions & 23 deletions app/views/uploads/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<%= form_with(model: upload, class: "contents", url: upload_path) do |form| %>
<%= form_with(model: upload, class: "flex flex-col gap-4 py-4", url: upload_path) do |form| %>
<% if upload.errors.any? %>
<div
id="error_explanation"
class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3"
>
<h2><%= pluralize(upload.errors.count, "error") %>
prohibited this upload from being saved:</h2>

<ul>
<% upload.errors.each do |error| %>
<li><%= error.full_message %></li>
Expand All @@ -15,29 +12,65 @@
</div>
<% end %>

<div class="my-5">
<%= form.label :data %>
<%= form.file_field :data,
class:
"block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
</div>
<%= form.label :data,
class:
"
flex flex-col items-center justify-center w-full h-64 border-2 border-gray-300
border-dashed rounded-lg cursor-pointer border border-gray-800 background-white",
data: { controller: "drop" } do %>
<div class="flex flex-col items-center justify-center pt-5 pb-6 text-gray-500">
<%= inline_svg "upload.svg",
class: "icon-upload w-8 h-8 mb-4",
data: {
drop_target: "uploadIcon",
} %>
<%= inline_svg "file.svg",
class: "icon-file w-8 h-8 mb-4 hidden",
data: {
drop_target: "fileIcon",
} %>

<div data-drop-target="text" class="text-center">
<p class="mb-2 text-sm "><span class="font-semibold">Click to upload</span>
or drag and drop</p>
<p class="text-xs">(MAX. 1MB)</p>
</div>
</div>

<%= form.file_field :data, class: "hidden", data: { action: "change->drop#display" } %>
<% end %>

<div class="my-5">
<%= form.label :expiry %>
<%= form.datetime_field :expiry,
<div class="flex flex-col sm:flex-row align-center grow gap-4">
<div class="w-full">
<%= form.label :expiry %>
<%= form.select(
:expiry,
[
["1 Minutes", 1.minute.from_now],
["10 Minutes", 10.minutes.from_now],
["30 Minutes", 30.minutes.from_now],
["60 Minutes", 60.minutes.from_now],
],
{},
class:
"block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full",
) %>
</div>

<div class="w-full">
<%= form.label :remaining_uses, "Uses" %>
<%= form.number_field :remaining_uses,
min: "1",
max: "5",
class:
"block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
</div>
</div>

<div class="my-5">
<%= form.label :remaining_uses %>
<%= form.number_field :remaining_uses,
class:
"block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
</div>

<div class="inline">
<%= form.submit class:
"rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
<div class="flex flex-row justify-center align-center w-full py-8">
<%= form.submit "Upload",
class:
"block text-white font-semibold outline-none bg-gray-800 w-full rounded-full grow px-12 py-3 text-sm focus:outline-none focus:ring sm:w-auto
" %>
</div>
<% end %>
Loading

0 comments on commit 2153163

Please sign in to comment.