Skip to content

Commit 6e775a2

Browse files
feat: increment opened count when opening link from local server (#255) (#381)
Co-authored-by: Yogesh Choudhary Paliyal <yogeshpaliyal.foss@gmail.com>
1 parent f44d5d5 commit 6e775a2

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

app/src/main/assets/index.html

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,14 +677,14 @@ <h3 class="text-lg font-semibold text-gray-800 line-clamp-2 flex-1">
677677
` : ''}
678678
679679
<div class="mt-4 pt-4 border-t border-gray-100">
680-
<a href="${escapeHtml(link.link)}"
681-
target="_blank"
680+
<button
681+
onclick="handleOpenLink(${link.id}, '${escapeHtml(link.link)}')"
682682
class="w-full bg-gradient-to-r from-primary-500 to-secondary-500 hover:from-primary-600 hover:to-secondary-600 text-white py-2 px-4 rounded-lg text-sm font-medium transition-all duration-200 transform hover:scale-105 flex items-center justify-center gap-2">
683683
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
684684
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"></path>
685685
</svg>
686686
Open Link
687-
</a>
687+
</button>
688688
</div>
689689
</div>
690690
</div>
@@ -693,6 +693,21 @@ <h3 class="text-lg font-semibold text-gray-800 line-clamp-2 flex-1">
693693
`;
694694
}
695695

696+
// Handle opening a link and incrementing count
697+
async function handleOpenLink(id, url) {
698+
// Open link in new tab
699+
window.open(url, '_blank');
700+
701+
// Increment count in background
702+
try {
703+
await fetch(`/api/links/increment-count?id=${id}`, { method: 'POST' });
704+
// Optional: refresh links to see updated count
705+
setTimeout(loadLinks, 1000);
706+
} catch (error) {
707+
console.error('Error incrementing count:', error);
708+
}
709+
}
710+
696711
// Populate tag filter dropdown
697712
function populateTagFilter() {
698713
const tagFilter = document.getElementById('tagFilter');

app/src/main/java/com/yogeshpaliyal/deepr/server/LocalServerRepositoryImpl.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,24 @@ open class LocalServerRepositoryImpl(
328328
)
329329
}
330330
}
331+
332+
post("/api/links/increment-count") {
333+
try {
334+
val id = call.request.queryParameters["id"]?.toLongOrNull()
335+
if (id != null) {
336+
accountViewModel.incrementOpenedCount(id)
337+
call.respond(HttpStatusCode.OK, SuccessResponse("Count incremented"))
338+
} else {
339+
call.respond(HttpStatusCode.BadRequest, ErrorResponse("Invalid link ID"))
340+
}
341+
} catch (e: Exception) {
342+
Log.e("LocalServer", "Error incrementing count", e)
343+
call.respond(
344+
HttpStatusCode.InternalServerError,
345+
ErrorResponse("Error incrementing count: ${e.message}"),
346+
)
347+
}
348+
}
331349
}
332350
}
333351

0 commit comments

Comments
 (0)