Skip to content

Commit

Permalink
Add gql id building functions
Browse files Browse the repository at this point in the history
  • Loading branch information
owi92 committed Nov 2, 2023
1 parent aa618fb commit a48be0d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
5 changes: 2 additions & 3 deletions frontend/src/routes/Embed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Translation, useTranslation } from "react-i18next";
import { graphql, PreloadedQuery, usePreloadedQuery } from "react-relay";
import { unreachable } from "@opencast/appkit";

import { isSynced } from "../util";
import { eventId, isSynced } from "../util";
import { GlobalErrorBoundary } from "../util/err";
import { loadQuery } from "../relay";
import { makeRoute } from "../rauta";
Expand Down Expand Up @@ -46,9 +46,8 @@ export const EmbedVideoRoute = makeRoute(url => {
return null;
}
const videoId = decodeURIComponent(params[1]);
const eventId = `ev${videoId}`;

const queryRef = loadQuery<EmbedQuery>(query, { id: eventId });
const queryRef = loadQuery<EmbedQuery>(query, { id: eventId(videoId) });

return {
render: () => <ErrorBoundary>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/Series.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RootLoader } from "../layout/Root";
import { Nav } from "../layout/Navigation";
import { PageTitle } from "../layout/header/ui";
import { WaitingPage } from "../ui/Waiting";
import { isSynced } from "../util";
import { isSynced, seriesId } from "../util";

import { NotFound } from "./NotFound";
import { SeriesByOpencastIdQuery } from "./__generated__/SeriesByOpencastIdQuery.graphql";
Expand Down Expand Up @@ -65,7 +65,7 @@ export const DirectSeriesRoute = makeRoute(url => {
rootRealm { ... NavigationData }
}
`;
const queryRef = loadQuery<SeriesByIdQuery>(query, { id: `sr${id}` });
const queryRef = loadQuery<SeriesByIdQuery>(query, { id: seriesId(id) });


return {
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/routes/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
translatedConfig,
currentRef,
secondsToTimeString,
eventId,
} from "../util";
import { BREAKPOINT_SMALL, BREAKPOINT_MEDIUM } from "../GlobalStyle";
import { Button, LinkButton } from "../ui/Button";
Expand Down Expand Up @@ -102,8 +103,7 @@ export const VideoRoute = makeRoute(url => {
}
`;
const realmPath = "/" + realmPathParts.join("/");
const eventId = `ev${videoId}`;
const queryRef = loadQuery<VideoPageInRealmQuery>(query, { id: eventId, realmPath });
const queryRef = loadQuery<VideoPageInRealmQuery>(query, { id: eventId(videoId), realmPath });

return {
render: () => <RootLoader
Expand Down Expand Up @@ -154,8 +154,7 @@ export const DirectVideoRoute = makeRoute(url => {
}
`;
const videoId = decodeURIComponent(params[1]);
const eventId = `ev${videoId}`;
const queryRef = loadQuery<VideoPageDirectLinkQuery>(query, { id: eventId });
const queryRef = loadQuery<VideoPageDirectLinkQuery>(query, { id: eventId(videoId) });

return matchedDirectRoute(query, queryRef);
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/manage/Video/Shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { b64regex } from "../../util";
import { Thumbnail } from "../../../ui/Video";
import { SharedVideoManageQuery } from "./__generated__/SharedVideoManageQuery.graphql";
import { Link } from "../../../router";
import { isExperimentalFlagSet, keyOfId } from "../../../util";
import { eventId, isExperimentalFlagSet, keyOfId } from "../../../util";


export const PAGE_WIDTH = 1100;
Expand All @@ -38,7 +38,7 @@ export const makeManageVideoRoute = (
}

const videoId = decodeURIComponent(params[1]);
const queryRef = loadQuery<SharedVideoManageQuery>(query, { id: `ev${videoId}` });
const queryRef = loadQuery<SharedVideoManageQuery>(query, { id: eventId(videoId) });

return {
render: () => <RootLoader
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export function keyOfId(id: string): string {
return id.substring(2);
}

/** Constructs event ID for graphQL by adding the "ev" prefix. */
export const eventId = (key: string) => `ev${key}`;

/** Constructs series ID for graphQL by adding the "sr" prefix. */
export const seriesId = (key: string) => `sr${key}`;

/**
* Create a comparison function for `Array.prototype.sort` comparing whatever
* the given key function returns as numbers.
Expand Down

0 comments on commit a48be0d

Please sign in to comment.