@gamepark/react-client 7.1.0 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/Chat/ChatChannel.d.ts +1 -1
  2. package/dist/Chat/index.d.ts +0 -1
  3. package/dist/Chat/index.js +0 -1
  4. package/dist/Chat/index.js.map +1 -1
  5. package/dist/Deckbuilding/useDeleteDeck.d.ts +5 -5
  6. package/dist/Deckbuilding/useDeleteDeck.js +9 -8
  7. package/dist/Deckbuilding/useDeleteDeck.js.map +1 -1
  8. package/dist/Deckbuilding/useMyDecks.d.ts +5 -5
  9. package/dist/Deckbuilding/useMyDecks.js +3 -6
  10. package/dist/Deckbuilding/useMyDecks.js.map +1 -1
  11. package/dist/Deckbuilding/useSaveDeck.d.ts +12 -7
  12. package/dist/Deckbuilding/useSaveDeck.js +16 -8
  13. package/dist/Deckbuilding/useSaveDeck.js.map +1 -1
  14. package/dist/Hooks/useChatMessages.d.ts +12 -2
  15. package/dist/Hooks/useChatMessages.js +30 -26
  16. package/dist/Hooks/useChatMessages.js.map +1 -1
  17. package/dist/Hooks/useMessageAuthor.js +5 -6
  18. package/dist/Hooks/useMessageAuthor.js.map +1 -1
  19. package/dist/Hooks/useRematch.d.ts +59 -5
  20. package/dist/Hooks/useRematch.js +5 -7
  21. package/dist/Hooks/useRematch.js.map +1 -1
  22. package/dist/Hooks/useSendMessage.d.ts +2 -4
  23. package/dist/Hooks/useSendMessage.js +2 -4
  24. package/dist/Hooks/useSendMessage.js.map +1 -1
  25. package/dist/Rematch/RematchQueries.d.ts +4 -4
  26. package/dist/User/User.d.ts +1 -1
  27. package/dist/User/useMe.js +4 -6
  28. package/dist/User/useMe.js.map +1 -1
  29. package/dist/api/Client/GameClientAPI.d.ts +6 -7
  30. package/dist/api/Client/GameClientAPI.js +32 -35
  31. package/dist/api/Client/GameClientAPI.js.map +1 -1
  32. package/dist/api/Client/GameNotificationsListener.js +15 -18
  33. package/dist/api/Client/GameNotificationsListener.js.map +1 -1
  34. package/dist/api/Client/RemoteGameLoader.js +45 -45
  35. package/dist/api/Client/RemoteGameLoader.js.map +1 -1
  36. package/dist/api/Client/apollo-client.js +0 -19
  37. package/dist/api/Client/apollo-client.js.map +1 -1
  38. package/dist/api/Client/index.d.ts +0 -1
  39. package/dist/api/Client/index.js +0 -1
  40. package/dist/api/Client/index.js.map +1 -1
  41. package/dist/api/boardGameCredits.d.ts +17 -0
  42. package/dist/api/boardGameCredits.js +127 -0
  43. package/dist/api/boardGameCredits.js.map +1 -0
  44. package/dist/api/boardGameNames.d.ts +9 -0
  45. package/dist/api/boardGameNames.js +119 -0
  46. package/dist/api/boardGameNames.js.map +1 -0
  47. package/dist/api/index.d.ts +3 -0
  48. package/dist/api/index.js +3 -0
  49. package/dist/api/index.js.map +1 -1
  50. package/dist/api/trpc/TRPCProvider.d.ts +3 -0
  51. package/dist/api/trpc/TRPCProvider.js +19 -0
  52. package/dist/api/trpc/TRPCProvider.js.map +1 -0
  53. package/dist/api/trpc/client.d.ts +6 -0
  54. package/dist/api/trpc/client.js +34 -0
  55. package/dist/api/trpc/client.js.map +1 -0
  56. package/dist/api/trpc/index.d.ts +2 -0
  57. package/dist/api/trpc/index.js +3 -0
  58. package/dist/api/trpc/index.js.map +1 -0
  59. package/dist/index.d.ts +0 -2
  60. package/dist/index.js +0 -2
  61. package/dist/index.js.map +1 -1
  62. package/package.json +69 -63
@@ -1,4 +1,4 @@
1
- import { Message } from './index';
1
+ import { Message } from './Message';
2
2
  export type ChatChannel = {
3
3
  name: string;
4
4
  messages: Message[];
@@ -1,2 +1 @@
1
1
  export * from './ChatChannel';
2
- export * from './Message';
@@ -1,3 +1,2 @@
1
1
  export * from './ChatChannel';
2
- export * from './Message';
3
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Chat/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Chat/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
@@ -1,5 +1,5 @@
1
- import { useMutation } from '@apollo/client/react';
2
- export declare const DELETE_DECK: import("@apollo/client").DocumentNode;
3
- export declare function useDeleteDeck(): useMutation.ResultTuple<unknown, {
4
- [x: string]: any;
5
- }, import("@apollo/client").ApolloCache>;
1
+ export declare function useDeleteDeck(boardGame: string): {
2
+ mutate: (id: string) => void;
3
+ mutateAsync: (id: string) => Promise<string>;
4
+ isLoading: boolean;
5
+ };
@@ -1,10 +1,11 @@
1
- import { gql } from '@apollo/client';
2
- import { useMutation } from '@apollo/client/react';
3
- import { MY_DECKS } from './useMyDecks';
4
- export const DELETE_DECK = gql `mutation SaveDeck($id: String) {
5
- deleteDeck(id: $id)
6
- }`;
7
- export function useDeleteDeck() {
8
- return useMutation(DELETE_DECK, { refetchQueries: [MY_DECKS] });
1
+ import { trpc } from '../api';
2
+ export function useDeleteDeck(boardGame) {
3
+ const utils = trpc.useUtils();
4
+ const mutation = trpc.deck.deleteDeck.useMutation({
5
+ onSuccess: (deletedId) => {
6
+ utils.deck.myDecks.setData(boardGame, (oldDecks) => oldDecks?.filter((deck) => deck.id !== deletedId));
7
+ }
8
+ });
9
+ return { mutate: mutation.mutate, mutateAsync: mutation.mutateAsync, isLoading: mutation.isPending };
9
10
  }
10
11
  //# sourceMappingURL=useDeleteDeck.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDeleteDeck.js","sourceRoot":"","sources":["../../src/Deckbuilding/useDeleteDeck.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEvC,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAA;;EAE5B,CAAA;AAEF,MAAM,UAAU,aAAa;IAC3B,OAAO,WAAW,CAAC,WAAW,EAAE,EAAE,cAAc,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;AACjE,CAAC"}
1
+ {"version":3,"file":"useDeleteDeck.js","sourceRoot":"","sources":["../../src/Deckbuilding/useDeleteDeck.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAE7B,MAAM,UAAU,aAAa,CAAC,SAAiB;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAA;IAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;QAChD,SAAS,EAAE,CAAC,SAAS,EAAE,EAAE;YACvB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAA;QACxG,CAAC;KACF,CAAC,CAAA;IACF,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAA;AACtG,CAAC"}
@@ -1,6 +1,6 @@
1
- import { useQuery } from '@apollo/client/react';
2
1
  import { Deck } from './Deck';
3
- export declare const MY_DECKS: import("@apollo/client").DocumentNode;
4
- export declare function useMyDecks(boardGame: string): useQuery.Result<{
5
- myDecks: Deck[];
6
- }, import("@apollo/client").OperationVariables, "complete" | "empty" | "streaming", import("@apollo/client").OperationVariables>;
2
+ export declare function useMyDecks(boardGame: string): {
3
+ data: Deck[] | undefined;
4
+ isLoading: boolean;
5
+ refetch: () => void;
6
+ };
@@ -1,9 +1,6 @@
1
- import { gql } from '@apollo/client';
2
- import { useQuery } from '@apollo/client/react';
3
- export const MY_DECKS = gql `query MyDecks($boardGame: String!) {
4
- myDecks(boardGame: $boardGame) { id name cards }
5
- }`;
1
+ import { trpc } from '../api';
6
2
  export function useMyDecks(boardGame) {
7
- return useQuery(MY_DECKS, { variables: { boardGame } });
3
+ const query = trpc.deck.myDecks.useQuery(boardGame);
4
+ return { data: query.data, isLoading: query.isLoading, refetch: query.refetch };
8
5
  }
9
6
  //# sourceMappingURL=useMyDecks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMyDecks.js","sourceRoot":"","sources":["../../src/Deckbuilding/useMyDecks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAG/C,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,CAAA;;EAEzB,CAAA;AAEF,MAAM,UAAU,UAAU,CAAC,SAAiB;IAC1C,OAAO,QAAQ,CAAsB,QAAQ,EAAE,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,EAAE,CAAC,CAAA;AAC9E,CAAC"}
1
+ {"version":3,"file":"useMyDecks.js","sourceRoot":"","sources":["../../src/Deckbuilding/useMyDecks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAG7B,MAAM,UAAU,UAAU,CAAC,SAAiB;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;IACnD,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAA;AACjF,CAAC"}
@@ -1,8 +1,13 @@
1
- import { useMutation } from '@apollo/client/react';
2
1
  import { Deck } from './Deck';
3
- export declare const SAVE_DECK: import("@apollo/client").DocumentNode;
4
- export declare function useSaveDeck(): useMutation.ResultTuple<{
5
- saveDeck: Deck;
6
- }, {
7
- [x: string]: any;
8
- }, import("@apollo/client").ApolloCache>;
2
+ type SaveDeckInput = {
3
+ id?: string;
4
+ boardGame: string;
5
+ name: string;
6
+ cards: number[];
7
+ };
8
+ export declare function useSaveDeck(boardGame: string): {
9
+ mutate: (input: SaveDeckInput) => void;
10
+ mutateAsync: (input: SaveDeckInput) => Promise<Deck>;
11
+ isLoading: boolean;
12
+ };
13
+ export {};
@@ -1,10 +1,18 @@
1
- import { gql } from '@apollo/client';
2
- import { useMutation } from '@apollo/client/react';
3
- import { MY_DECKS } from './useMyDecks';
4
- export const SAVE_DECK = gql `mutation SaveDeck($id: String, $boardGame: String!, $name: String!, $cards: [Int!]!) {
5
- saveDeck(id: $id, boardGame: $boardGame, name: $name, cards: $cards) { id name cards }
6
- }`;
7
- export function useSaveDeck() {
8
- return useMutation(SAVE_DECK, { refetchQueries: [MY_DECKS] });
1
+ import { trpc } from '../api';
2
+ export function useSaveDeck(boardGame) {
3
+ const utils = trpc.useUtils();
4
+ const mutation = trpc.deck.saveDeck.useMutation({
5
+ onSuccess: (savedDeck, variables) => {
6
+ utils.deck.myDecks.setData(boardGame, (oldDecks) => {
7
+ if (!oldDecks)
8
+ return [savedDeck];
9
+ if (variables.id) {
10
+ return oldDecks.map((deck) => (deck.id === savedDeck.id ? savedDeck : deck));
11
+ }
12
+ return [savedDeck, ...oldDecks];
13
+ });
14
+ }
15
+ });
16
+ return { mutate: mutation.mutate, mutateAsync: mutation.mutateAsync, isLoading: mutation.isPending };
9
17
  }
10
18
  //# sourceMappingURL=useSaveDeck.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSaveDeck.js","sourceRoot":"","sources":["../../src/Deckbuilding/useSaveDeck.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA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S,EAAE,CAAA;AACtG,CAAC"}
@@ -1,6 +1,16 @@
1
- import { Message } from '../Chat';
1
+ export type Message = {
2
+ id: string;
3
+ userId: string;
4
+ text: string;
5
+ date: Date;
6
+ };
2
7
  export declare function useChatMessages(gameId: string, onMessageReceived?: (message: Message) => void): {
3
- messages: Message[];
8
+ messages: {
9
+ id: string;
10
+ userId: string;
11
+ text: string;
12
+ date: Date;
13
+ }[];
4
14
  hasMoreMessages: boolean;
5
15
  loading: boolean;
6
16
  fetchMore: () => Promise<void>;
@@ -1,45 +1,49 @@
1
- import { gql } from '@apollo/client';
2
- import { useQuery } from '@apollo/client/react';
3
1
  import { useEffect, useState } from 'react';
4
- import { pusherClient } from '../api';
5
- const GET_CHAT_MESSAGES = gql `query ChatMessages($channel: String!, $limit: Int, $maxDate: DateTime) {
6
- chatChannel(name: $channel) {
7
- name
8
- messages(limit: $limit, maxDate: $maxDate) {
9
- id userId text date
10
- }
11
- }
12
- }`;
2
+ import { pusherClient, trpc } from '../api';
13
3
  export function useChatMessages(gameId, onMessageReceived) {
14
4
  const [subscribed, setSubscribed] = useState(false);
15
5
  const [hasMoreMessages, setHasMoreMessages] = useState(true);
16
- const { data, loading, fetchMore, client } = useQuery(GET_CHAT_MESSAGES, {
17
- variables: { channel: `game=${gameId}`, limit: 50 }, skip: !subscribed
18
- });
19
- const messages = (data?.chatChannel?.messages ?? []);
6
+ const utils = trpc.useUtils();
7
+ const { data: messages = [], isLoading } = trpc.chat.getMessages.useQuery({ channel: `game=${gameId}`, limit: 50 }, { enabled: subscribed });
20
8
  useEffect(() => {
21
9
  const channel = pusherClient.subscribe(`game=${gameId}`);
22
10
  channel.bind('pusher:subscription_succeeded', () => setSubscribed(true));
23
- channel.bind('message', (message) => {
24
- if (message) {
25
- client.writeFragment({
26
- id: `ChatChannel:{"name":"game=${gameId}"}`,
27
- fragment: gql `fragment ChatMessages on ChatChannel { messages { id userId text date } }`,
28
- data: { messages: [{ __typename: 'Message', ...message }] }
11
+ channel.bind('message', (pusherMessage) => {
12
+ if (pusherMessage) {
13
+ const message = { ...pusherMessage, date: new Date(pusherMessage.date) };
14
+ utils.chat.getMessages.setData({ channel: `game=${gameId}`, limit: 50 }, (oldData) => {
15
+ return [message, ...(oldData ?? [])];
29
16
  });
30
17
  if (onMessageReceived)
31
18
  onMessageReceived(message);
32
19
  }
33
20
  });
34
21
  return () => pusherClient.unsubscribe(`game=${gameId}`);
35
- }, []);
22
+ }, [gameId, onMessageReceived, utils]);
23
+ const fetchMore = async () => {
24
+ if (messages.length === 0)
25
+ return;
26
+ const oldestMessage = messages[messages.length - 1];
27
+ const olderMessages = await utils.client.chat.getMessages.query({
28
+ channel: `game=${gameId}`,
29
+ limit: 10,
30
+ cursor: oldestMessage.date
31
+ });
32
+ if (olderMessages && olderMessages.length > 0) {
33
+ utils.chat.getMessages.setData({ channel: `game=${gameId}`, limit: 50 }, (oldData = []) => {
34
+ return [...oldData, ...olderMessages];
35
+ });
36
+ setHasMoreMessages(olderMessages.length === 10);
37
+ }
38
+ else {
39
+ setHasMoreMessages(false);
40
+ }
41
+ };
36
42
  return {
37
43
  messages,
38
44
  hasMoreMessages,
39
- loading,
40
- fetchMore: () => fetchMore({ variables: { limit: 10, maxDate: messages[messages.length - 1].date } }).then((result) => {
41
- setHasMoreMessages(result.data !== undefined && result.data.chatChannel.messages.length === 10);
42
- })
45
+ loading: isLoading,
46
+ fetchMore
43
47
  };
44
48
  }
45
49
  //# sourceMappingURL=useChatMessages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useChatMessages.js","sourceRoot":"","sources":["../../src/Hooks/useChatMessages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;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I,CAAC,WAAW,CAAC,KAAK,CAAC;YAC9D,OAAO,EAAE,QAAQ,MAAM,EAAE;YACzB,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,aAAa,CAAC,IAAI;SAC3B,CAAC,CAAA;QAEF,IAAI,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAE9C,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,EAAE,EAAE;gBACxF,OAAO,CAAC,GAAG,OAAO,EAAE,GAAG,aAAa,CAAC,CAAA;YACvC,CAAC,CAAC,CAAA;YACF,kBAAkB,CAAC,aAAa,CAAC,MAAM,KAAK,EAAE,CAAC,CAAA;QACjD,CAAC;aAAM,CAAC;YACN,kBAAkB,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC;IACH,CAAC,CAAA;IAED,OAAO;QACL,QAAQ;QACR,eAAe;QACf,OAAO,EAAE,SAAS;QAClB,SAAS;KACV,CAAA;AACH,CAAC"}
@@ -1,14 +1,13 @@
1
- import { useQuery } from '@apollo/client/react';
2
- import { GET_MESSAGE_AUTHOR } from '../api';
1
+ import { trpc } from '../api';
3
2
  import { useGameSelector } from '../Store';
4
3
  const query = new URLSearchParams(window.location.search);
5
4
  export function useMessageAuthor(author) {
6
5
  const players = useGameSelector(state => state.players);
7
6
  const player = players.find(p => p.userId === author);
8
- const skip = !!player || query.get('game') === null;
9
- const { data } = useQuery(GET_MESSAGE_AUTHOR, { variables: { id: author }, skip: skip });
10
- const avatar = player?.avatar ?? data?.user.avatar;
11
- const name = player?.name ?? data?.user.name;
7
+ const enabled = !player && query.get('game') !== null;
8
+ const { data } = trpc.user.getUser.useQuery(author, { enabled });
9
+ const avatar = player?.avatar ?? data?.avatar;
10
+ const name = player?.name ?? data?.name;
12
11
  return { avatar, name };
13
12
  }
14
13
  //# sourceMappingURL=useMessageAuthor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMessageAuthor.js","sourceRoot":"","sources":["../../src/Hooks/useMessageAuthor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAG1C,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;AAEzD,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACvD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAA;IACrD,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,CAAA;IACnD,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAiB,kBAAkB,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IACxG,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,IAAI,IAAI,EAAE,IAAI,CAAC,MAAM,CAAA;IAClD,MAAM,IAAI,GAAG,MAAM,EAAE,IAAI,IAAI,IAAI,EAAE,IAAI,CAAC,IAAI,CAAA;IAC5C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;AACzB,CAAC"}
1
+ {"version":3,"file":"useMessageAuthor.js","sourceRoot":"","sources":["../../src/Hooks/useMessageAuthor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE1C,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;AAEzD,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACvD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAA;IACrD,MAAM,OAAO,GAAG,CAAC,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,CAAA;IACrD,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;IAChE,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,IAAI,IAAI,EAAE,MAAM,CAAA;IAC7C,MAAM,IAAI,GAAG,MAAM,EAAE,IAAI,IAAI,IAAI,EAAE,IAAI,CAAA;IACvC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;AACzB,CAAC"}
@@ -1,7 +1,61 @@
1
- import { CanRematchData } from '../Rematch';
2
1
  export declare function useRematch(): {
3
- game: CanRematchData | undefined;
4
- rematch: () => Promise<import("@apollo/client").ApolloClient.MutateResult<unknown> | import("@apollo/client").ApolloClient.QueryResult<{
5
- game: CanRematchData;
6
- }>>;
2
+ game: {
3
+ id: string;
4
+ canRematch: boolean;
5
+ rematch?: {
6
+ id: string;
7
+ players: {
8
+ id: any;
9
+ userId: string;
10
+ ready: boolean;
11
+ name?: string;
12
+ }[];
13
+ startDate?: Date;
14
+ };
15
+ } | undefined;
16
+ rematch: () => Promise<{
17
+ id: string;
18
+ canRematch: boolean;
19
+ rematch?: {
20
+ id: string;
21
+ players: {
22
+ id: any;
23
+ userId: string;
24
+ ready: boolean;
25
+ name?: string;
26
+ }[];
27
+ startDate?: Date;
28
+ };
29
+ } | import("@tanstack/query-core").QueryObserverResult<{
30
+ id: string;
31
+ canRematch: boolean;
32
+ rematch?: {
33
+ id: string;
34
+ players: {
35
+ id: any;
36
+ userId: string;
37
+ ready: boolean;
38
+ name?: string;
39
+ }[];
40
+ startDate?: Date;
41
+ };
42
+ }, import("@trpc/client").TRPCClientErrorLike<{
43
+ input: string;
44
+ output: {
45
+ id: string;
46
+ canRematch: boolean;
47
+ rematch?: {
48
+ id: string;
49
+ players: {
50
+ id: any;
51
+ userId: string;
52
+ ready: boolean;
53
+ name?: string;
54
+ }[];
55
+ startDate?: Date;
56
+ };
57
+ };
58
+ transformer: true;
59
+ errorShape: import("@trpc/server").TRPCDefaultErrorShape;
60
+ }>>>;
7
61
  };
@@ -1,19 +1,17 @@
1
- import { useMutation, useQuery } from '@apollo/client/react';
2
1
  import { useEffect } from 'react';
3
- import { pusherClient } from '../api';
4
- import { CAN_REMATCH, REMATCH } from '../Rematch';
2
+ import { pusherClient, trpc } from '../api';
5
3
  export function useRematch() {
6
4
  const query = new URLSearchParams(window.location.search);
7
5
  const gameId = query.get('game');
8
- const canRematchResult = useQuery(CAN_REMATCH, { variables: { id: gameId } });
9
- const game = canRematchResult.data?.game;
10
- const [rematch] = useMutation(REMATCH);
6
+ const canRematchResult = trpc.rematch.canRematch.useQuery(gameId, { enabled: !!gameId });
7
+ const game = canRematchResult.data;
8
+ const rematchMutation = trpc.rematch.requestRematch.useMutation();
11
9
  useEffect(() => {
12
10
  const channel = pusherClient.subscribe('rematch=' + gameId);
13
11
  channel.bind('rematch', () => canRematchResult.refetch());
14
12
  channel.bind('pusher:subscription_succeeded', () => canRematchResult.refetch());
15
13
  return () => pusherClient.unsubscribe('rematch=' + gameId);
16
14
  }, []);
17
- return { game, rematch: () => rematch({ variables: { gameId } }).catch(() => canRematchResult.refetch()) };
15
+ return { game, rematch: () => rematchMutation.mutateAsync(gameId).catch(() => canRematchResult.refetch()) };
18
16
  }
19
17
  //# sourceMappingURL=useRematch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useRematch.js","sourceRoot":"","sources":["../../src/Hooks/useRematch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,WAAW,EAAkB,OAAO,EAAE,MAAM,YAAY,CAAA;AAEjE,MAAM,UAAU,UAAU;IACxB,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACzD,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAChC,MAAM,gBAAgB,GAAG,QAAQ,CAA2B,WAAW,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAA;IACvG,MAAM,IAAI,GAAG,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAA;IACxC,MAAM,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;IACtC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,YAAY,CAAC,SAAS,CAAC,UAAU,GAAG,MAAM,CAAC,CAAA;QAC3D,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAA;QACzD,OAAO,CAAC,IAAI,CAAC,+BAA+B,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAA;QAC/E,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,UAAU,GAAG,MAAM,CAAC,CA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Y,CAAC,WAAW,CAAC,UAAU,GAAG,MAAM,CAAC,CAAA;IAC5D,CAAC,EAAE,EAAE,CAAC,CAAA;IACN,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,EAAE,CAAA;AAC7G,CAAC"}
@@ -1,4 +1,2 @@
1
- import { useMutation } from '@apollo/client/react';
2
- export declare function useSendMessage(): useMutation.ResultTuple<unknown, {
3
- [x: string]: any;
4
- }, import("@apollo/client").ApolloCache>;
1
+ import { trpc } from '../api';
2
+ export declare function useSendMessage(): ReturnType<typeof trpc.chat.sendMessage.useMutation>;
@@ -1,7 +1,5 @@
1
- import { gql } from '@apollo/client';
2
- import { useMutation } from '@apollo/client/react';
3
- const SEND_MESSAGE = gql `mutation SendMessage($channel: String!, $text: String!) { sendMessage(channel: $channel, text: $text) { date } }`;
1
+ import { trpc } from '../api';
4
2
  export function useSendMessage() {
5
- return useMutation(SEND_MESSAGE);
3
+ return trpc.chat.sendMessage.useMutation();
6
4
  }
7
5
  //# sourceMappingURL=useSendMessage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSendMessage.js","sourceRoot":"","sources":["../../src/Hooks/useSendMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAElD,MAAM,YAAY,GAAG,GAAG,CAAA,kHAAkH,CAAA;AAE1I,MAAM,UAAU,cAAc;IAC5B,OAAO,WAAW,CAAC,YAAY,CAAC,CAAA;AAClC,CAAC"}
1
+ {"version":3,"file":"useSendMessage.js","sourceRoot":"","sources":["../../src/Hooks/useSendMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAO7B,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAA;AAC5C,CAAC"}
@@ -1,4 +1,4 @@
1
- export declare const CAN_REMATCH: import("@apollo/client").DocumentNode;
1
+ export declare const CAN_REMATCH: import("graphql").DocumentNode;
2
2
  export interface CanRematchData {
3
3
  id: string;
4
4
  canRematch: boolean;
@@ -14,6 +14,6 @@ export interface RematchPlayerData {
14
14
  userId: string;
15
15
  ready: boolean;
16
16
  }
17
- export declare const REMATCH: import("@apollo/client").DocumentNode;
18
- export declare const ACCEPT_REMATCH: import("@apollo/client").DocumentNode;
19
- export declare const REFUSE_REMATCH: import("@apollo/client").DocumentNode;
17
+ export declare const REMATCH: import("graphql").DocumentNode;
18
+ export declare const ACCEPT_REMATCH: import("graphql").DocumentNode;
19
+ export declare const REFUSE_REMATCH: import("graphql").DocumentNode;
@@ -2,5 +2,5 @@ export type User = {
2
2
  id: string;
3
3
  name?: string;
4
4
  avatar?: any;
5
- subscriptionSince: string | null;
5
+ isSubscriber: boolean;
6
6
  };
@@ -1,11 +1,9 @@
1
- import { gql } from '@apollo/client';
2
- import { useQuery } from '@apollo/client/react';
3
1
  import { useMemo } from 'react';
4
- import { AVATAR_INFO } from '../api';
5
- const GET_ME = gql `query Me { me { user { id name subscriptionSince avatar {...AvatarInfo} } } } ${AVATAR_INFO}`;
2
+ import { trpc } from '../api';
6
3
  export function useMe() {
7
4
  const urlSearchParams = new URLSearchParams(window.location.search);
8
- const fetchPolicy = useMemo(() => process.env.NODE_ENV !== 'production' && !urlSearchParams.get('game') && !urlSearchParams.get('mode') ? 'cache-only' : 'cache-first', []);
9
- return useQuery(GET_ME, { ssr: false, fetchPolicy }).data?.me;
5
+ const enabled = useMemo(() => process.env.NODE_ENV === 'production' || !!urlSearchParams.get('game') || !!urlSearchParams.get('mode'), []);
6
+ const { data } = trpc.user.getMe.useQuery(undefined, { enabled });
7
+ return data ? { user: data } : undefined;
10
8
  }
11
9
  //# sourceMappingURL=useMe.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMe.js","sourceRoot":"","sources":["../../src/User/useMe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAGpC,MAAM,MAAM,GAAG,GAAG,CAAA,iFAAiF,WAAW,EAAE,CAAA;AAEhH,MAAM,UAAU,KAAK;IACnB,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACnE,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,CAC7B,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,EACpI,EAAE,CAAC,CAAA;IACP,OAAO,QAAQ,CAAyB,MAAM,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAA;AACvF,CAAC"}
1
+ {"version":3,"file":"useMe.js","sourceRoot":"","sources":["../../src/User/useMe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAG7B,MAAM,UAAU,KAAK;IACnB,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACnE,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CACzB,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,EACvG,EAAE,CAAC,CAAA;IACP,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;IACjE,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAY,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AAClD,CAAC"}
@@ -1,10 +1,6 @@
1
1
  import { Dispatch } from 'redux';
2
2
  import { GameAPI } from '../GameAPI';
3
- export declare const PLATFORM_URI: string;
4
- export declare const AVATAR_INFO: import("@apollo/client").DocumentNode;
5
- export declare const PLAYERS_TIME: import("@apollo/client").DocumentNode;
6
- export declare const NOTIFICATIONS: import("@apollo/client").DocumentNode;
7
- export declare const GET_MESSAGE_AUTHOR: import("@apollo/client").DocumentNode;
3
+ export declare const PLATFORM_URI: any;
8
4
  export declare class GameClientAPI<Move = any, PlayerId = any> implements GameAPI<Move, PlayerId> {
9
5
  private dispatch?;
10
6
  private readonly gameId;
@@ -15,10 +11,13 @@ export declare class GameClientAPI<Move = any, PlayerId = any> implements GameAP
15
11
  play(move: Move): void;
16
12
  undo(action: number | string): void;
17
13
  private executePendingActions;
18
- private handleGameMessageResult;
14
+ private handleTRPCResult;
19
15
  eject(playerId: PlayerId): void;
20
16
  giveUp(): void;
21
17
  onError(error: unknown): void;
22
18
  playTutorialMoves(): void;
23
- claimVictory(): Promise<import("@apollo/client").ApolloClient.MutateResult<unknown>>;
19
+ claimVictory(): Promise<{
20
+ id: string;
21
+ endDate?: Date;
22
+ }>;
24
23
  }
@@ -1,24 +1,9 @@
1
- import { CombinedGraphQLErrors, gql } from '@apollo/client';
1
+ import { TRPCClientError } from '@trpc/client';
2
2
  import { receiveNotifications } from '../../Actions';
3
3
  import { reportFailure } from '../../Actions/reportFailure';
4
4
  import { Failure } from '../../Failure';
5
- import { getApolloClient } from './apollo-client';
6
- export const PLATFORM_URI = process.env.PLATFORM_URI ?? 'https://game-park.com';
7
- export const AVATAR_INFO = gql `fragment AvatarInfo on Avataaar {accessoriesType clotheColor clotheType eyeType eyebrowType facialHairType facialHairColor graphicType hairColor mouthType skinColor topType}`;
8
- export const PLAYERS_TIME = gql `fragment PlayerTime on Player { time { availableTime cumulatedDownTime cumulatedPlayTime cumulatedWaitForMeTime highestDownTime highestPlayTime lastChange playing weightedWaitForMeTime } }`;
9
- export const NOTIFICATIONS = gql `fragment Notifications on GameNotification { playerId ... on MovePlayedNotification { actionId moveView consequences } ... on MoveUndoneNotification { actionId moveUndone } }`;
10
- const PLAY = gql `mutation PlayMoves($gameId: String!, $moves: [JSON!]!) { playMoves(gameId: $gameId, moves: $moves) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ${NOTIFICATIONS} ${PLAYERS_TIME}`;
11
- const UNDO = gql `mutation UndoMoves($gameId: String!, $actions: [String!]!) { undoMoves(gameId: $gameId, actions: $actions) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ${NOTIFICATIONS} ${PLAYERS_TIME}`;
12
- const EJECT_PLAYER = gql `mutation EjectPlayer($gameId: String!, $playerId: JSON!) { ejectPlayer(gameId: $gameId, playerId: $playerId) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ${NOTIFICATIONS} ${PLAYERS_TIME}`;
13
- const GIVE_UP = gql `mutation GiveUp($gameId: String!) { giveUp(gameId: $gameId) { notifications { ...Notifications } index players { id ...PlayerTime } date } } ${NOTIFICATIONS} ${PLAYERS_TIME}`;
14
- const CLAIM_VICTORY = gql `mutation ClaimVictory($gameId: String!) { claimVictory(gameId: $gameId) { id endDate } }`;
15
- export const GET_MESSAGE_AUTHOR = gql `
16
- query GetMessageAuthor($id: String!) {
17
- user(id: $id) {
18
- id name avatar {...AvatarInfo}
19
- }
20
- } ${AVATAR_INFO}
21
- `;
5
+ import { trpcClient } from '../trpc';
6
+ export const PLATFORM_URI = import.meta.env?.VITE_PLATFORM_URI ?? process.env.PLATFORM_URI ?? 'https://game-park.com';
22
7
  export class GameClientAPI {
23
8
  dispatch;
24
9
  gameId;
@@ -70,14 +55,16 @@ export class GameClientAPI {
70
55
  if (this.pendingActions.length > 0) {
71
56
  const pendingAction = this.pendingActions.shift();
72
57
  if (pendingAction.type == 'PLAY') {
73
- this.ongoingAction = getApolloClient().mutate({
74
- mutation: PLAY, variables: { gameId: this.gameId, moves: pendingAction.moves }
75
- }).then(result => result.data && this.handleGameMessageResult(result.data.playMoves));
58
+ this.ongoingAction = trpcClient.game.playMoves.mutate({
59
+ gameId: this.gameId,
60
+ moves: pendingAction.moves
61
+ }).then(result => this.handleTRPCResult(result));
76
62
  }
77
63
  else if (pendingAction.type === 'UNDO') {
78
- this.ongoingAction = getApolloClient().mutate({
79
- mutation: UNDO, variables: { gameId: this.gameId, actions: pendingAction.actions }
80
- }).then(result => result.data && this.handleGameMessageResult(result.data.undoMoves));
64
+ this.ongoingAction = trpcClient.game.undoMoves.mutate({
65
+ gameId: this.gameId,
66
+ actions: pendingAction.actions
67
+ }).then(result => this.handleTRPCResult(result));
81
68
  }
82
69
  if (this.ongoingAction) {
83
70
  this.ongoingAction = this.ongoingAction.catch(error => this.onError(error)).finally(() => this.executePendingActions());
@@ -87,22 +74,32 @@ export class GameClientAPI {
87
74
  delete this.ongoingAction;
88
75
  }
89
76
  }
90
- handleGameMessageResult({ date, index, notifications, players }) {
91
- this.dispatch(receiveNotifications({ notifications, notificationsIndex: index, players, serverTime: Date.parse(date) }));
77
+ handleTRPCResult(result) {
78
+ this.dispatch(receiveNotifications({
79
+ notifications: result.notifications,
80
+ notificationsIndex: result.index,
81
+ players: result.players.map(p => ({
82
+ id: p.id,
83
+ time: p.time ? {
84
+ ...p.time,
85
+ lastChange: p.time.lastChange.toISOString(),
86
+ availableTime: p.time.availableTime ?? null
87
+ } : undefined
88
+ })),
89
+ serverTime: result.date.getTime()
90
+ }));
92
91
  }
93
92
  eject(playerId) {
94
- getApolloClient().mutate({ mutation: EJECT_PLAYER, variables: { gameId: this.gameId, playerId } })
95
- .then(result => result.data && this.handleGameMessageResult(result.data.ejectPlayer));
93
+ trpcClient.game.ejectPlayer.mutate({ gameId: this.gameId, playerId })
94
+ .then(result => this.handleTRPCResult(result));
96
95
  }
97
96
  giveUp() {
98
- getApolloClient().mutate({ mutation: GIVE_UP, variables: { gameId: this.gameId } })
99
- .then(result => result.data && this.handleGameMessageResult(result.data.giveUp));
97
+ trpcClient.game.giveUp.mutate({ gameId: this.gameId })
98
+ .then(result => this.handleTRPCResult(result));
100
99
  }
101
100
  onError(error) {
102
- if (CombinedGraphQLErrors.is(error)) {
103
- for (const graphqlFormattedError of error.errors) {
104
- this.dispatch(reportFailure(graphqlFormattedError.message));
105
- }
101
+ if (error instanceof TRPCClientError) {
102
+ this.dispatch(reportFailure(error.message));
106
103
  }
107
104
  else {
108
105
  this.dispatch(reportFailure(Failure.NETWORK));
@@ -112,7 +109,7 @@ export class GameClientAPI {
112
109
  console.error('Tutorial should only be played with local API');
113
110
  }
114
111
  claimVictory() {
115
- return getApolloClient().mutate({ mutation: CLAIM_VICTORY, variables: { gameId: this.gameId } });
112
+ return trpcClient.game.claimVictory.mutate({ gameId: this.gameId });
116
113
  }
117
114
  }
118
115
  //# sourceMappingURL=GameClientAPI.js.map