Skip to content

Commit

Permalink
feat(Login): Add a Flight Director core for seeing which clients are …
Browse files Browse the repository at this point in the history
…logged in.

Closes #274
  • Loading branch information
alexanderson1993 committed Apr 16, 2022
1 parent a2dd5f4 commit 386a95f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
19 changes: 19 additions & 0 deletions client/src/cores/LoginCore/data.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {DataContext} from "server/src/utils/DataContext";

export const subscriptions = {
clients(context: DataContext) {
if (!context.flight) return [];
const serverClients = Object.values(context.server.clients);
const flightClients = context.flight?.clients || {};
const clients = serverClients
.map(client => {
const flightClient = flightClients[client.id];
return {
...client.toJSON(),
...flightClient?.toJSON(),
};
})
.filter(client => client.stationId);
return clients;
},
};
27 changes: 27 additions & 0 deletions client/src/cores/LoginCore/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import useCardData from "client/src/context/useCardData";

export function LoginCore() {
const data = useCardData<"LoginCore">();
return (
<div className="prose prose-invert w-full mx-auto">
<table>
<thead>
<tr>
<th>Client</th>
<th>Station</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{data.clients.map(client => (
<tr key={client.id}>
<td>{client.name}</td>
<td>{client.stationId}</td>
<td>{client.loginName}</td>
</tr>
))}
</tbody>
</table>
</div>
);
}
1 change: 1 addition & 0 deletions client/src/cores/dataList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as LoginCore from "./LoginCore/data";
1 change: 1 addition & 0 deletions client/src/cores/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {LoginCore} from "./LoginCore";
5 changes: 4 additions & 1 deletion client/src/utils/cardData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {DataContext, UnionToIntersection} from "server/src/utils/types";
import * as allData from "../cards/dataList";
import * as allCards from "../cards/dataList";
import * as allCores from "../cores/dataList";

const allData = {...allCards, ...allCores};

// @ts-expect-error The default value duplicates everything else. No need to include it.
const {["default"]: defaultValue, ...cardData} = allData;
Expand Down
2 changes: 2 additions & 0 deletions server/src/inputs/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ export const clientInputs = {
if (context.flightClient) {
context.flightClient.loginName = params.loginName;
}
pubsub.publish("clients");
pubsub.publish("client", {clientId: context.clientId});
},
clientLogout: (context: DataContext) => {
if (context.flightClient) {
context.flightClient.loginName = "";
}
pubsub.publish("client", {clientId: context.clientId});
pubsub.publish("clients");
},
clientOverrideStation: async (
context: DataContext,
Expand Down

0 comments on commit 386a95f

Please sign in to comment.