From 084d77cd788f9d49bc00ecff4ccaac1a3dfd51c4 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Tue, 12 Dec 2023 18:24:59 -0800 Subject: [PATCH] Linting --- src/apps/news/AppNews.tsx | 2 +- src/apps/news/news.hooks.ts | 7 +++---- src/common/app.routes.ts | 14 +++++++++++--- src/modules/backend/backend.router.ts | 2 +- .../llms/vendors/mistral/MistralSourceSetup.tsx | 4 ++-- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/apps/news/AppNews.tsx b/src/apps/news/AppNews.tsx index 09ef21aab..e5f1d6e5a 100644 --- a/src/apps/news/AppNews.tsx +++ b/src/apps/news/AppNews.tsx @@ -78,7 +78,7 @@ export function AppNews() { {!!news && {news?.map((ni, idx) => { - const firstCard = idx === 0; + // const firstCard = idx === 0; const hasCardAfter = news.length < NewsItems.length; const showExpander = hasCardAfter && (idx === news.length - 1); const addPadding = false; //!firstCard; // || showExpander; diff --git a/src/apps/news/news.hooks.ts b/src/apps/news/news.hooks.ts index d1cb7993c..fbfb27c45 100644 --- a/src/apps/news/news.hooks.ts +++ b/src/apps/news/news.hooks.ts @@ -1,14 +1,13 @@ import * as React from 'react'; import { shallow } from 'zustand/shallow'; -import { useRouter } from 'next/router'; +import { navigateToNews } from '~/common/app.routes'; import { useAppStateStore } from '~/common/state/store-appstate'; import { incrementalVersion } from './news.data'; export function useShowNewsOnUpdate() { - const { push: routerPush } = useRouter(); const { usageCount, lastSeenNewsVersion } = useAppStateStore(state => ({ usageCount: state.usageCount, lastSeenNewsVersion: state.lastSeenNewsVersion, @@ -17,9 +16,9 @@ export function useShowNewsOnUpdate() { const isNewsOutdated = (lastSeenNewsVersion || 0) < incrementalVersion; if (isNewsOutdated && usageCount > 2) { // Disable for now - void routerPush('/news'); + void navigateToNews(); } - }, [lastSeenNewsVersion, routerPush, usageCount]); + }, [lastSeenNewsVersion, usageCount]); } export function useMarkNewsAsSeen() { diff --git a/src/common/app.routes.ts b/src/common/app.routes.ts index f60ef62cc..e3281e602 100644 --- a/src/common/app.routes.ts +++ b/src/common/app.routes.ts @@ -15,7 +15,7 @@ export const ROUTE_APP_LINK_CHAT = '/link/chat/:linkId'; export const ROUTE_APP_NEWS = '/news'; const ROUTE_CALLBACK_OPENROUTER = '/link/callback_openrouter'; -export const getIndexLink = () => ROUTE_INDEX; +// Get Paths export const getCallbackUrl = (source: 'openrouter') => { const callbackUrl = new URL(window.location.href); @@ -31,10 +31,11 @@ export const getCallbackUrl = (source: 'openrouter') => { export const getChatLinkRelativePath = (chatLinkId: string) => ROUTE_APP_LINK_CHAT.replace(':linkId', chatLinkId); -const navigateFn = (path: string) => (replace?: boolean): Promise => - Router[replace ? 'replace' : 'push'](path); + +/// Simple Navigation export const navigateToIndex = navigateFn(ROUTE_INDEX); + export const navigateToChat = async (conversationId?: DConversationId) => { if (conversationId) { await Router.push( @@ -54,6 +55,13 @@ export const navigateToNews = navigateFn(ROUTE_APP_NEWS); export const navigateBack = Router.back; +function navigateFn(path: string) { + return (replace?: boolean): Promise => Router[replace ? 'replace' : 'push'](path); +} + + +/// Launch Apps + export interface AppCallQueryParams { conversationId: string; personaId: string; diff --git a/src/modules/backend/backend.router.ts b/src/modules/backend/backend.router.ts index e7af30f56..ad207a75e 100644 --- a/src/modules/backend/backend.router.ts +++ b/src/modules/backend/backend.router.ts @@ -42,7 +42,7 @@ export const backendRouter = createTRPCRouter({ /* Exchange the OpenrRouter 'code' (from PKCS) for an OpenRouter API Key */ exchangeOpenRouterKey: publicProcedure .input(z.object({ code: z.string() })) - .query(async ({ ctx, input }) => { + .query(async ({ input }) => { // Documented here: https://openrouter.ai/docs#oauth return await fetchJsonOrTRPCError<{ key: string }, { code: string }>('https://openrouter.ai/api/v1/auth/keys', 'POST', {}, { code: input.code, diff --git a/src/modules/llms/vendors/mistral/MistralSourceSetup.tsx b/src/modules/llms/vendors/mistral/MistralSourceSetup.tsx index 11633d978..8cfa57d46 100644 --- a/src/modules/llms/vendors/mistral/MistralSourceSetup.tsx +++ b/src/modules/llms/vendors/mistral/MistralSourceSetup.tsx @@ -18,7 +18,7 @@ const MISTRAL_REG_LINK = 'https://console.mistral.ai/'; export function MistralSourceSetup(props: { sourceId: DModelSourceId }) { // external state - const { source, sourceSetupValid, sourceHasLLMs, access, updateSetup } = + const { source, sourceSetupValid, access, updateSetup } = useSourceSetup(props.sourceId, ModelVendorMistral); // derived state @@ -30,7 +30,7 @@ export function MistralSourceSetup(props: { sourceId: DModelSourceId }) { // fetch models const { isFetching, refetch, isError, error } = apiQuery.llmOpenAI.listModels.useQuery({ access }, { - enabled: false, + enabled: shallFetchSucceed, onSuccess: models => source && useModelsStore.getState().setLLMs( models.models.map(model => modelDescriptionToDLLM(model, source)), props.sourceId,