appview/pages: add panel to link an ATURI on pdsls #753

merged
opened by oppi.li targeting master from push-toykwqpnvqrs
Changed files
+54 -1
appview
pages
templates
repo
+6 -1
appview/pages/funcmap.go
···
"splitOn": func(s, sep string) []string {
return strings.Split(s, sep)
},
+
"string": func(v any) string {
+
return fmt.Sprint(v)
+
},
"int64": func(a int) int64 {
return int64(a)
},
···
u, _ := url.PathUnescape(s)
return u
},
-
+
"safeUrl": func(s string) template.URL {
+
return template.URL(s)
+
},
"tinyAvatar": func(handle string) string {
return p.AvatarUrl(handle, "tiny")
},
+48
appview/pages/templates/repo/fragments/externalLinkPanel.html
···
+
{{ define "repo/fragments/externalLinkPanel" }}
+
<div id="at-uri-panel" class="px-2 md:px-0">
+
<div class="flex justify-between items-center gap-2">
+
<span class="text-sm py-1 font-bold text-gray-500 dark:text-gray-400 capitalize">AT URI</span>
+
<div class="flex items-center gap-2">
+
<button
+
onclick="copyToClipboard(this)"
+
class="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
+
title="Copy to clipboard">
+
{{ i "copy" "w-4 h-4" }}
+
</button>
+
<a
+
href="https://pdsls.dev/{{.}}"
+
class="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
+
title="View in PDSls">
+
{{ i "arrow-up-right" "w-4 h-4" }}
+
</a>
+
</div>
+
</div>
+
<span
+
class="font-mono text-sm select-all cursor-pointer block max-w-full overflow-x-auto whitespace-nowrap scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600"
+
onclick="window.getSelection().selectAllChildren(this)"
+
title="{{.}}"
+
data-aturi="{{ . | string | safeUrl }}"
+
>{{.}}</span>
+
+
+
</div>
+
+
<script>
+
function copyToClipboard(button) {
+
const container = document.getElementById("at-uri-panel");
+
const urlSpan = container?.querySelector('[data-aturi]');
+
const text = urlSpan?.getAttribute('data-aturi');
+
console.log("copying to clipboard", text)
+
if (!text) return;
+
+
navigator.clipboard.writeText(text).then(() => {
+
const originalContent = button.innerHTML;
+
button.innerHTML = `{{ i "check" "w-4 h-4" }}`;
+
setTimeout(() => {
+
button.innerHTML = originalContent;
+
}, 2000);
+
});
+
}
+
</script>
+
{{ end }}
+