Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

Commit

Permalink
fix(taboule): expect 'publicKey' to be passed as query param
Browse files Browse the repository at this point in the history
  • Loading branch information
ascariandrea committed Oct 17, 2022
1 parent dbc67df commit 4cba72e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 35 deletions.
18 changes: 9 additions & 9 deletions packages/taboule/src/components/Taboule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import {
GridColTypeDef,
GridEventListener,
} from '@mui/x-data-grid';
import { APIError } from '@shared/errors/APIError';
import { AppError } from '@shared/errors/AppError';
import { GetLogger } from '@shared/logger';
import { ObservableQuery } from 'avenger/lib/Query';
import { ParsedInfo } from '@yttrex/shared/src/models/Metadata';
import * as QR from 'avenger/lib/QueryResult';
import { WithQueries } from 'avenger/lib/react';
import debug from 'debug';
Expand All @@ -19,11 +18,14 @@ import { PathReporter } from 'io-ts/lib/PathReporter';
import * as React from 'react';
import * as config from '../config';
import { TabouleDataProvider } from '../state';
import { Results, SearchRequestInput, TabouleQueries } from '../state/queries';
import {
EndpointQuery,
SearchRequestInput,
TabouleQueries,
} from '../state/queries';
import { TabouleQueryKey } from '../state/types';
import { ErrorOverlay } from './ErrorOverlay';
import ExpandView from './expand-view/ExpandView';
import { ParsedInfo } from '@yttrex/shared/src/models/Metadata';
import './Taboule.css';

debug.enable(process.env.DEBUG ?? '');
Expand Down Expand Up @@ -95,11 +97,9 @@ export const Taboule = <Q extends keyof TabouleQueries>({
() => TabouleDataProvider(baseURL),
[baseURL]
);
const query: ObservableQuery<
SearchRequestInput,
APIError,
Results<any>
> = tabouleQueries.queries[queryKey];
const query: EndpointQuery<SearchRequestInput, any> = tabouleQueries.queries[
queryKey
] as any;

const { inputs, ...queryConfig } = React.useMemo(
() =>
Expand Down
54 changes: 33 additions & 21 deletions packages/taboule/src/state/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Step } from '@shared/models/Step';
import { ListMetadataQuery } from '@yttrex/shared/endpoints/v2/metadata.endpoints';

export interface SearchRequestInput {
Params: any;
Params: { publicKey: string };
Query: SearchQuery;
}

Expand All @@ -37,20 +37,27 @@ export interface Results<T> {
content: T[];
}

type EndpointQuery<C> = CachedQuery<SearchRequestInput, APIError, Results<C>>;
export type EndpointQuery<Q extends {}, C> = CachedQuery<
Q,
APIError,
Results<C>
>;

export interface TabouleQueries {
YCAIccRelatedUsers: EndpointQuery<ChannelRelated>;
youtubeGetExperimentById: EndpointQuery<Step>;
youtubeGetExperimentList: EndpointQuery<GuardoniExperiment>;
youtubePersonalSearches: EndpointQuery<SearchMetadata>;
youtubePersonalAds: EndpointQuery<any>;
youtubePersonalHomes: EndpointQuery<HomeMetadata>;
youtubePersonalVideos: EndpointQuery<VideoMetadata>;
YCAIccRelatedUsers: EndpointQuery<any, ChannelRelated>;
youtubeGetExperimentById: EndpointQuery<any, Step>;
youtubeGetExperimentList: EndpointQuery<
SearchRequestInput,
GuardoniExperiment
>;
youtubePersonalSearches: EndpointQuery<SearchRequestInput, SearchMetadata>;
youtubePersonalAds: EndpointQuery<SearchRequestInput, any>;
youtubePersonalHomes: EndpointQuery<SearchRequestInput, HomeMetadata>;
youtubePersonalVideos: EndpointQuery<SearchRequestInput, VideoMetadata>;
// tik tok
tikTokPersonalHTMLSummary: EndpointQuery<SummaryHTMLMetadata>;
tikTokPersonalSearch: EndpointQuery<TikTokPSearchMetadata>;
tikTokSearches: EndpointQuery<TKSearchMetadata>;
tikTokPersonalHTMLSummary: EndpointQuery<any, SummaryHTMLMetadata>;
tikTokPersonalSearch: EndpointQuery<any, TikTokPSearchMetadata>;
tikTokSearches: EndpointQuery<any, TKSearchMetadata>;
}

interface GetTabouleQueriesProps {
Expand Down Expand Up @@ -153,7 +160,6 @@ export const GetTabouleQueries = ({
researchTag: undefined,
format: 'json',
nature: 'home',
publicKey: 'H7AsuUszehN4qKTj2GYYwNNzkJVqUQBRo2wgKevzeUwx',
},
}),
TE.map((content) => {
Expand Down Expand Up @@ -193,14 +199,14 @@ export const GetTabouleQueries = ({
pipe(
YTAPI.v2.Metadata.ListMetadata({
Query: {
...input.Params,
...input.Query,
amount: '20' as any,
skip: '0' as any,
experimentId: undefined,
researchTag: undefined,
format: 'json',
nature: 'video',
publicKey: 'H7AsuUszehN4qKTj2GYYwNNzkJVqUQBRo2wgKevzeUwx',
},
}),
TE.map((content) => {
Expand Down Expand Up @@ -231,12 +237,13 @@ export const GetTabouleQueries = ({
researchTag: undefined,
format: 'json',
nature: 'search',
publicKey: 'H7AsuUszehN4qKTj2GYYwNNzkJVqUQBRo2wgKevzeUwx',
},
}),
TE.map((content) => {
const x = content.filter((c) => c.type === 'search');
return x as any[] as SearchMetadata[];
const x = content.filter(
(c) => c.type === 'search'
) as any[] as SearchMetadata[];
return x;
}),
TE.map((content) => ({
total: content.length ?? 0,
Expand All @@ -263,16 +270,21 @@ export const GetTabouleQueries = ({
);

const tikTokPersonalSearch = queryStrict<
SearchRequestInput,
SearchRequestInput & { Params: { publicKey: string } },
APIError,
Results<TikTokPSearchMetadata>
>(
(input) =>
pipe(
YTAPI.v1.Public.GetPersonalSearchByPublicKey(input),
TK_API.v2.Personal.GetPersonalJSON({
Params: {
...input.Params,
what: 'search',
},
}),
TE.map((content) => ({
total: content.metadata.length,
content: content.metadata,
total: content.total,
content: content.content as any[],
}))
),
available
Expand Down
10 changes: 5 additions & 5 deletions platforms/yttrex/shared/src/models/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ export const ParsedInfo = t.strict(
verified: t.union([t.boolean, t.null]),
// foryou: t.union([t.string, t.undefined, t.null]),
parameter: t.union([t.string, t.undefined]),
params: t.union([t.record(t.string, t.string), t.undefined]),
params: t.union([t.record(t.string, t.string), t.undefined, t.null]),
title: t.union([t.string, t.undefined]),
recommendedHref: t.string,
recommendedTitle: t.union([t.string, t.undefined]),
recommendedSource: t.union([t.string, t.null, t.undefined]),
recommendedLength: t.union([t.number, t.undefined]),
recommendedDisplayL: t.union([t.string, t.undefined]),
recommendedDisplayL: t.union([t.string, t.undefined, t.null]),
// moment duration as string
recommendedPubTime: t.union([t.any, t.undefined]),
publicationTime: t.union([DateFromISOString, t.undefined]),
recommendedThumbnail: t.union([t.string, t.undefined]),
recommendedPubTime: t.union([t.any, t.undefined, t.null]),
publicationTime: t.union([DateFromISOString, t.undefined, t.null]),
recommendedThumbnail: t.union([t.string, t.undefined, t.null]),
recommendedViews: t.union([t.number, t.undefined]),
views: t.union([t.number, t.undefined]),
},
Expand Down

0 comments on commit 4cba72e

Please sign in to comment.