diff options
-rw-r--r-- | api/api.ts | 1 | ||||
-rw-r--r-- | api/user/info.py | 5 | ||||
-rw-r--r-- | pages/user.tsx | 12 |
3 files changed, 16 insertions, 2 deletions
@@ -6,6 +6,7 @@ export interface userInfo { registered?: number, type?: string, username?: string, + friends: number, relation?: "none"|"friends"|"incoming"|"outgoing"|"blocked", }; diff --git a/api/user/info.py b/api/user/info.py index e720e56..b60593e 100644 --- a/api/user/info.py +++ b/api/user/info.py @@ -18,6 +18,10 @@ def get_relation_to(user_1_id, user_2_id): if relation[2] == "block" and relation[0] == user_1_id: return "blocked" return "none" +def count_friends(user_id): + query = cursor.execute("select type from social where (user_1_id = ? or user_2_id = ?) and type = \"friendship\"", [user_id, user_id]).fetchall() + return len(query) + def format_user(user_id, viewer = ''): user = cursor.execute("select " + ", ".join([ "username", @@ -34,6 +38,7 @@ def format_user(user_id, viewer = ''): "registered": user[3], "avatar": user[4], "status": user[5], + "friends": count_friends(user_id) } if viewer: formatted_user["relation"] = get_relation_to(viewer, user_id) diff --git a/pages/user.tsx b/pages/user.tsx index c963550..01a2d23 100644 --- a/pages/user.tsx +++ b/pages/user.tsx @@ -290,7 +290,11 @@ export default function AccountPage() { return memberSince; })() }/> - <InfoModule icon={<PeopleOutlineOutlinedIcon/>} label="2 vrienden"/> + <InfoModule icon={<PeopleOutlineOutlinedIcon/>} label={(() => { + var label = user?.friends.toString() + " "; + label += user?.friends == 1 ? "vriend" : "vrienden"; + return label; + })()}/> <InfoModule icon={<Icon size={1} path={mdiEarth}/>} label="Nederland"/> </InfoSection> <InfoSection> @@ -298,7 +302,11 @@ export default function AccountPage() { <InfoModule icon={<Icon size={1} path={mdiEqual}/>} label={ gameInfo?.totals.draw + " keer gelijkspel" }/> <InfoModule icon={<ArrowDownwardOutlinedIcon style={{ color: "var(--disk-a-text)" }}/>} label={ gameInfo?.totals.lose + " keer verloren" }/> <InfoModule icon={<Icon size={1} path={mdiClipboardTextOutline}/>} label="Score: 400"/> - <InfoModule icon={<Icon size={1} path={mdiGamepadSquareOutline}/>} label={ gameInfo?.totals.games + " potjes" }/> + <InfoModule icon={<Icon size={1} path={mdiGamepadSquareOutline}/>} label={(() => { + var label = gameInfo?.totals.games.toString() + " "; + label += gameInfo?.totals.games == 1 ? "potje" : "potjes"; + return label; + })()}/> </InfoSection> <Vierkant> <RecentGames games={gameInfo?.games}/> |