diff --git a/frontend/src/ts/pages/friends.ts b/frontend/src/ts/pages/friends.ts index c617aa507..a9b261b77 100644 --- a/frontend/src/ts/pages/friends.ts +++ b/frontend/src/ts/pages/friends.ts @@ -17,6 +17,8 @@ import { SortedTable } from "../utils/sorted-table"; const pageElement = $(".page.pageFriends"); +let friendsTable: SortedTable | undefined = undefined; + const addFriendModal = new SimpleModal({ id: "addFriend", title: "Add a friend", @@ -103,12 +105,17 @@ async function fetchFriends(): Promise { $(".pageFriends .friends table").removeClass("hidden"); $(".pageFriends .friends .nodata").addClass("hidden"); - new SortedTable({ - table: ".pageFriends .friends table", - data: result.body.data, - buildRow: buildFriendRow, - initialSort: { property: "name", descending: false }, - }); + if (friendsTable === undefined) { + friendsTable = new SortedTable({ + table: ".pageFriends .friends table", + data: result.body.data, + buildRow: buildFriendRow, + initialSort: { property: "name", descending: false }, + }); + } else { + friendsTable.setData(result.body.data); + } + friendsTable.updateBody(); } } diff --git a/frontend/src/ts/utils/sorted-table.ts b/frontend/src/ts/utils/sorted-table.ts index 8e12c3f2d..9425c764a 100644 --- a/frontend/src/ts/utils/sorted-table.ts +++ b/frontend/src/ts/utils/sorted-table.ts @@ -1,4 +1,7 @@ -type Sort = { property: string; descending: boolean }; +type Sort = { + property: string; + descending: boolean; +}; type SortedTableOptions = { table: string;