@@ -8,18 +8,47 @@ async function loadBooks() {
88function displayBooks ( books ) {
99 const tbody = document . querySelector ( "#bookTable tbody" ) ;
1010 tbody . innerHTML = "" ;
11+
1112 books . forEach ( book => {
12- const row = `<tr>
13- <td>${ book [ "Book Title" ] } </td>
14- <td>${ book [ "Author" ] } </td>
15- <td>${ book [ "Barcode" ] } </td>
16- <td>${ book [ "Status" ] } </td>
17- <td>${ book [ "User" ] || "" } </td>
18- </tr>` ;
19- tbody . innerHTML += row ;
13+ const row = document . createElement ( "tr" ) ;
14+
15+ row . innerHTML = `
16+ <td>${ book [ "Book Title" ] } </td>
17+ <td>${ book [ "Author" ] } </td>
18+ <td>${ book [ "Barcode" ] } </td>
19+ <td>${ book [ "Status" ] } </td>
20+ <td>${ book [ "User" ] || "" } </td>
21+ <td>
22+ ${ book [ "Status" ] === "Checked Out" ? `<button onclick="checkInBook('${ book [ "Barcode" ] } ')">Check In</button>` : "" }
23+ </td>
24+ ` ;
25+
26+ tbody . appendChild ( row ) ;
27+ } ) ;
28+ }
29+ async function checkInBook ( barcode ) {
30+ const data = {
31+ barcode : barcode ,
32+ user : "" , // Clear user on check-in
33+ action : "checkin"
34+ } ;
35+
36+ await fetch ( "https://api.github.com/repos/USACE-RMC/RMCLakewoodLibrary/issues" , {
37+ method : "POST" ,
38+ headers : {
39+ "Authorization" : "token YOUR_GITHUB_TOKEN" , // Replace with secure proxy or backend
40+ "Accept" : "application/vnd.github.v3+json"
41+ } ,
42+ body : JSON . stringify ( {
43+ title : `Book checkin: ${ barcode } ` ,
44+ body : JSON . stringify ( data )
45+ } )
2046 } ) ;
47+
48+ alert ( "Book checked in! Refresh to see updates." ) ;
2149}
2250
51+
2352// Search functionality
2453document . getElementById ( "searchBox" ) . addEventListener ( "input" , async ( e ) => {
2554 const query = e . target . value . toLowerCase ( ) ;
0 commit comments