From 271cf1f407fc5ea22c3258739ae62dc0e8cf1fb7 Mon Sep 17 00:00:00 2001 From: Fishandchips321 Date: Sun, 22 Feb 2026 19:30:12 +0000 Subject: [PATCH] Got index server list working --- backend/src/Controllers/SearchController.cs | 21 ++ backend/src/Controllers/ServersController.cs | 26 ++ backend/src/JellyGlass-test.db-shm | Bin 0 -> 32768 bytes backend/src/JellyGlass-test.db-wal | 0 backend/src/Models/ServerDTO.cs | 17 ++ backend/src/Program.cs | 3 +- backend/src/Services/ClientService.cs | 51 ++++ backend/src/Services/IClientService.cs | 10 + backend/src/Services/IServerService.cs | 8 +- backend/src/Services/LibraryService.cs | 4 +- backend/src/Services/ServerService.cs | 42 +-- frontend/package-lock.json | 280 ++++++++++++++++++ frontend/package.json | 1 + .../ServerList/ServerCard/ServerCard.tsx | 2 +- .../src/Components/ServerList/ServerList.tsx | 20 +- .../ServerSearchResult/ServerSearchResult.tsx | 2 +- frontend/src/Lib/Servers.ts | 21 +- frontend/src/Lib/api.ts | 2 + frontend/src/index.tsx | 2 +- 19 files changed, 445 insertions(+), 67 deletions(-) create mode 100644 backend/src/Controllers/SearchController.cs create mode 100644 backend/src/Controllers/ServersController.cs create mode 100644 backend/src/JellyGlass-test.db-shm create mode 100644 backend/src/JellyGlass-test.db-wal create mode 100644 backend/src/Models/ServerDTO.cs create mode 100644 backend/src/Services/ClientService.cs create mode 100644 backend/src/Services/IClientService.cs create mode 100644 frontend/src/Lib/api.ts diff --git a/backend/src/Controllers/SearchController.cs b/backend/src/Controllers/SearchController.cs new file mode 100644 index 0000000..3fb5313 --- /dev/null +++ b/backend/src/Controllers/SearchController.cs @@ -0,0 +1,21 @@ +using Microsoft.AspNetCore.Mvc; + +namespace JellyGlass.Controllers; + +[ApiController] +[Route("[controller]")] +public class SearchController : ControllerBase +{ + private ILogger _logger; + + public SearchController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public async Task handleSearch([FromQuery] string searchTerm) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/backend/src/Controllers/ServersController.cs b/backend/src/Controllers/ServersController.cs new file mode 100644 index 0000000..a38be5d --- /dev/null +++ b/backend/src/Controllers/ServersController.cs @@ -0,0 +1,26 @@ +using JellyGlass.Services; +using Microsoft.AspNetCore.Mvc; + +namespace JellyGlass.Controllers; + +[ApiController] +[Route("[controller]")] +public class ServersController : ControllerBase +{ + private ILogger _logger; + private IServerService _service; + + public ServersController(ILogger logger, IServerService service) + { + _logger = logger; + _service = service; + } + + [HttpGet] + public async Task getServers() + { + var servers = await _service.GetServers(); + + return Ok(servers); + } +} \ No newline at end of file diff --git a/backend/src/JellyGlass-test.db-shm b/backend/src/JellyGlass-test.db-shm new file mode 100644 index 0000000000000000000000000000000000000000..fe9ac2845eca6fe6da8a63cd096d9cf9e24ece10 GIT binary patch literal 32768 zcmeIuAr62r3(dbConnectionString); builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddTransient(); var app = builder.Build(); diff --git a/backend/src/Services/ClientService.cs b/backend/src/Services/ClientService.cs new file mode 100644 index 0000000..92caead --- /dev/null +++ b/backend/src/Services/ClientService.cs @@ -0,0 +1,51 @@ +using JellyGlass.Exceptions; +using JellyGlass.Repositories; + +namespace JellyGlass.Services; + +public class ClientService : IClientService +{ + private IServerRepository _repository; + private static JellyfinApiClient[] _clients = []; + private ILogger _logger; + + public ClientService(IServerRepository repository, ILogger logger) + { + _repository = repository; + _logger = logger; + } + + public async Task GetJellyfinClients() + { + if (!_clients.Any()) + { + await LoadClients(); + } + + return _clients; + } + + private async Task LoadClients() + { + var servers = await _repository.GetServers(); + var clients = new List(); + + foreach (var server in servers) + { + var client = new JellyfinApiClient(server.Url, server.Username, server.Password); + + try + { + await client.Authenticate(); + } + catch (JellyfinApiClientException e) + { + + } + + clients.Add(client); + } + + _clients = clients.ToArray(); + } +} \ No newline at end of file diff --git a/backend/src/Services/IClientService.cs b/backend/src/Services/IClientService.cs new file mode 100644 index 0000000..137e365 --- /dev/null +++ b/backend/src/Services/IClientService.cs @@ -0,0 +1,10 @@ +using JellyGlass.Repositories; + +namespace JellyGlass.Services; + +public interface IClientService +{ + public Task GetJellyfinClients(); + // public JellyfinApiClient GetClientForServer(string url); + // public JellyfinApiClient GetClientForServerId(string serverId); +} \ No newline at end of file diff --git a/backend/src/Services/IServerService.cs b/backend/src/Services/IServerService.cs index 82c633b..c0e034c 100644 --- a/backend/src/Services/IServerService.cs +++ b/backend/src/Services/IServerService.cs @@ -1,10 +1,10 @@ -using JellyGlass.Repositories; + + +using JellyGlass.Models; namespace JellyGlass.Services; public interface IServerService { - public Task GetJellyfinClients(); - // public JellyfinApiClient GetClientForServer(string url); - // public JellyfinApiClient GetClientForServerId(string serverId); + public Task GetServers(); } \ No newline at end of file diff --git a/backend/src/Services/LibraryService.cs b/backend/src/Services/LibraryService.cs index 41e6c51..882e4ed 100644 --- a/backend/src/Services/LibraryService.cs +++ b/backend/src/Services/LibraryService.cs @@ -4,9 +4,9 @@ namespace JellyGlass.Services; public class LibraryService : ILibraryService { - private IServerService _serverService; + private IClientService _serverService; - public LibraryService(IServerService serverService) + public LibraryService(IClientService serverService) { _serverService = serverService; } diff --git a/backend/src/Services/ServerService.cs b/backend/src/Services/ServerService.cs index 935d1b8..fd88c5b 100644 --- a/backend/src/Services/ServerService.cs +++ b/backend/src/Services/ServerService.cs @@ -1,4 +1,5 @@ -using JellyGlass.Exceptions; + + using JellyGlass.Models; using JellyGlass.Repositories; @@ -6,47 +7,24 @@ namespace JellyGlass.Services; public class ServerService : IServerService { - private IServerRepository _repository; - private static JellyfinApiClient[] _clients = []; - private ILogger _logger; + private readonly IServerRepository _repository; - public ServerService(IServerRepository repository, ILogger logger) + public ServerService(IServerRepository repository) { _repository = repository; - _logger = logger; } - public async Task GetJellyfinClients() - { - if (!_clients.Any()) - { - await LoadClients(); - } - - return _clients; - } - - private async Task LoadClients() + public async Task GetServers() { var servers = await _repository.GetServers(); - var clients = new List(); - foreach (var server in servers) + var dtos = new List(); + + foreach (var s in servers) { - var client = new JellyfinApiClient(server.Url, server.Username, server.Password); - - try - { - await client.Authenticate(); - } - catch (JellyfinApiClientException e) - { - - } - - clients.Add(client); + dtos.Add(new ServerDTO(s)); } - _clients = clients.ToArray(); + return dtos.ToArray(); } } \ No newline at end of file diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 85e62d5..4f87763 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -8,6 +8,7 @@ "name": "JellyGlass", "version": "0.0.0", "dependencies": { + "axios": "^1.13.5", "bootstrap": "^5.3.8", "react": "^19.2.0", "react-bootstrap": "^2.10.10", @@ -2258,6 +2259,23 @@ "dev": true, "license": "Python-2.0" }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, + "node_modules/axios": { + "version": "1.13.5", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.13.5.tgz", + "integrity": "sha512-cz4ur7Vb0xS4/KUN0tPWe44eqxrIu31me+fbang3ijiNscE129POzipJJA6zniq2C/Z6sJCjMimjS8Lc/GAs8Q==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.11", + "form-data": "^4.0.5", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -2343,6 +2361,19 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -2432,6 +2463,18 @@ "dev": true, "license": "MIT" }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2505,6 +2548,15 @@ "dev": true, "license": "MIT" }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/dequal": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", @@ -2534,6 +2586,20 @@ "csstype": "^3.0.2" } }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/electron-to-chromium": { "version": "1.5.302", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.302.tgz", @@ -2541,6 +2607,51 @@ "dev": true, "license": "ISC" }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/esbuild": { "version": "0.27.3", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.3.tgz", @@ -2881,6 +2992,42 @@ "dev": true, "license": "ISC" }, + "node_modules/follow-redirects": { + "version": "1.15.11", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.11.tgz", + "integrity": "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.5.tgz", + "integrity": "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -2896,6 +3043,15 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -2906,6 +3062,43 @@ "node": ">=6.9.0" } }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/glob-parent": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", @@ -2932,6 +3125,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -2942,6 +3147,45 @@ "node": ">=8" } }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "license": "MIT", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/hermes-estree": { "version": "0.25.1", "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.25.1.tgz", @@ -3176,6 +3420,36 @@ "yallist": "^3.0.2" } }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimatch": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.3.tgz", @@ -3419,6 +3693,12 @@ "react": ">=0.14.0" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", diff --git a/frontend/package.json b/frontend/package.json index 8624330..ad349f5 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -10,6 +10,7 @@ "preview": "vite preview" }, "dependencies": { + "axios": "^1.13.5", "bootstrap": "^5.3.8", "react": "^19.2.0", "react-bootstrap": "^2.10.10", diff --git a/frontend/src/Components/ServerList/ServerCard/ServerCard.tsx b/frontend/src/Components/ServerList/ServerCard/ServerCard.tsx index 4a319a2..0ba9ca0 100644 --- a/frontend/src/Components/ServerList/ServerCard/ServerCard.tsx +++ b/frontend/src/Components/ServerList/ServerCard/ServerCard.tsx @@ -10,7 +10,7 @@ interface ServerCardProps { const ServerCard = ({ name, online, linkTo }: ServerCardProps) => { return ( - + {name} diff --git a/frontend/src/Components/ServerList/ServerList.tsx b/frontend/src/Components/ServerList/ServerList.tsx index 3aeffea..56e4c2c 100644 --- a/frontend/src/Components/ServerList/ServerList.tsx +++ b/frontend/src/Components/ServerList/ServerList.tsx @@ -1,20 +1,20 @@ +import { useEffect, useState } from "react"; import ServerCard from "./ServerCard/ServerCard"; +import { getServerList, type Server } from "../../Lib/Servers"; -interface ServerListProps { - servers: Array; -} +const ServerList = () => { + const [servers, setServers] = useState>([]); -interface Server { - name: string; - online: boolean; - linkTo: string; -} + useEffect(() => { + getServerList().then(serverList => { + setServers(serverList); + }) + }) -const ServerList = ({ servers }: ServerListProps) => { return (
{servers.map(server => { - return () + return () })}
) diff --git a/frontend/src/Components/ServerSearch/ServerSearchResult/ServerSearchResult.tsx b/frontend/src/Components/ServerSearch/ServerSearchResult/ServerSearchResult.tsx index 481c256..b356262 100644 --- a/frontend/src/Components/ServerSearch/ServerSearchResult/ServerSearchResult.tsx +++ b/frontend/src/Components/ServerSearch/ServerSearchResult/ServerSearchResult.tsx @@ -11,7 +11,7 @@ const ServerSearchResult = ({ searchResult, server }: ServerSearchResultProps) = const resultUrl = getUrlForSearchResult(searchResult, server); return ( - +

{searchResult.name}

) diff --git a/frontend/src/Lib/Servers.ts b/frontend/src/Lib/Servers.ts index 3855304..b0f5676 100644 --- a/frontend/src/Lib/Servers.ts +++ b/frontend/src/Lib/Servers.ts @@ -1,6 +1,8 @@ +import axios from "axios"; +import { apiUrl } from "./api"; export interface Server { - name: string; + name?: string; id: string; online?: boolean; owner: string; @@ -8,18 +10,7 @@ export interface Server { } export const getServerList = async (): Promise> => { - return [{ - id: "asdf", - name: "test server", - owner: "meeeee", - url: "https://jellyfin.foxhawk.co.uk", - online: true - }, - { - id: "qwer", - name: "test server 2", - owner: "someone else", - url: "https://jellyfin.foxhawk.co.uk", - online: true - }]; + const response = await axios.get>(`${apiUrl}/servers`); + + return response.data; } \ No newline at end of file diff --git a/frontend/src/Lib/api.ts b/frontend/src/Lib/api.ts new file mode 100644 index 0000000..bc0d3d2 --- /dev/null +++ b/frontend/src/Lib/api.ts @@ -0,0 +1,2 @@ + +export const apiUrl = "http://localhost:5092" \ No newline at end of file diff --git a/frontend/src/index.tsx b/frontend/src/index.tsx index 0ffbb3b..5c89377 100644 --- a/frontend/src/index.tsx +++ b/frontend/src/index.tsx @@ -4,7 +4,7 @@ const Index = () => { return (

Available Servers

- +
) }