Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gateway): add cid copy button to directory listings #899

Merged
merged 5 commits into from
Apr 8, 2025

Conversation

VersaliXis
Copy link
Contributor

Fixes: #895

@VersaliXis VersaliXis requested a review from lidel as a code owner March 26, 2025 10:12

This comment was marked as outdated.

@gammazero gammazero added the need/maintainers-input Needs input from the current maintainer(s) label Apr 1, 2025
@gammazero
Copy link
Contributor

Could you upload a screenshot with this PR?

@VersaliXis
Copy link
Contributor Author

Sure! Here is what it looks like. If you want to change anything in the style, feel free to ask.

Copy button proposal

The code is pretty simple, here is a diff:

diff --git a/gateway/assets/directory.html b/gateway/assets/directory.html
index 888ecabf..9201ce83 100644
--- a/gateway/assets/directory.html
+++ b/gateway/assets/directory.html
@@ -59,6 +59,7 @@
             <a class="ipfs-hash" translate="no" href={{ if $root.DNSLink }}"https://cid.ipfs.tech/#{{ .Hash | urlEscape}}" target="_blank" rel="noreferrer noopener"{{ else }}"{{ $root.GatewayURL }}/ipfs/{{ .Hash | urlEscape}}?filename={{ .Name | urlEscape }}"{{ end }}>
               {{- .ShortHash -}}
             </a>
+            <button class="copy-button" onclick="navigator.clipboard.writeText('{{ .Hash }}')">Copy</button>
             {{ end }}
           </div>
           <div class="nowrap" title="Cumulative size of IPFS DAG (data + metadata)">{{ .Size }}</div>
diff --git a/gateway/assets/style.css b/gateway/assets/style.css
index a8dfdaf7..7e4512e7 100644
--- a/gateway/assets/style.css
+++ b/gateway/assets/style.css
@@ -66,6 +66,23 @@ a:visited {
        font-family: var(--monospace);
 }
 
+.copy-button {
+       color: #7f8491;
+       background-color: inherit;
+       border: 1px solid var(--dark-white);;
+       border-radius: 2px;
+       padding: 1px 2px;
+       cursor: copy;
+}
+
+.copy-button:hover {
+       background-color: var(--light-white);
+}
+
+.copy-button:active {
+       color: #00b0e9;
+}
+
 #header {
        align-items: center;
        background: var(--navy);

Including Adding the copy-icon in assets/icon.css
and Adding the description "Copy Hash" on mouse hover
lidel added 3 commits April 8, 2025 01:38
- hand on hover
- remove background-based feedback, switch to opacity on click
- add copy option to the top
@lidel lidel requested a review from a team as a code owner April 7, 2025 23:41
@lidel lidel changed the title [skip changelog] gateway: hash copy button feature in the directory listing feat(gateway): add cid copy button to directory listings Apr 7, 2025
@lidel lidel merged commit 58771d8 into ipfs:main Apr 8, 2025
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/maintainers-input Needs input from the current maintainer(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gateway: more responsive directory listing
5 participants