mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 09:01:19 +00:00
Compare commits
5 Commits
61c1ade631
...
feat/clien
| Author | SHA1 | Date | |
|---|---|---|---|
| 56d97a2c01 | |||
|
6e09e3c7b9
|
|||
|
924236181b
|
|||
|
f0a4c095b9
|
|||
|
8e7bce101d
|
@@ -22,6 +22,7 @@
|
||||
"@react-navigation/bottom-tabs": "^7.4.0",
|
||||
"@react-navigation/elements": "^2.6.3",
|
||||
"@react-navigation/native": "^7.1.8",
|
||||
"@tanstack/react-query": "^5.90.21",
|
||||
"expo": "~54.0.33",
|
||||
"expo-constants": "~18.0.13",
|
||||
"expo-dev-client": "~6.0.20",
|
||||
|
||||
6
apps/aelis-client/src/api/auth-middleware.ts
Normal file
6
apps/aelis-client/src/api/auth-middleware.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { ApiRequestMiddleware } from "./client"
|
||||
|
||||
export const authMiddleware: ApiRequestMiddleware = (_url, init) => {
|
||||
// TODO: placeholder auth middleware
|
||||
return init
|
||||
}
|
||||
39
apps/aelis-client/src/api/client.ts
Normal file
39
apps/aelis-client/src/api/client.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { createContext, useContext } from "react"
|
||||
|
||||
export type ApiRequestMiddleware = (
|
||||
url: Parameters<typeof fetch>[0],
|
||||
init: RequestInit,
|
||||
) => RequestInit
|
||||
|
||||
export class ApiClient {
|
||||
private readonly baseUrl: string
|
||||
private readonly middlewares: readonly ApiRequestMiddleware[]
|
||||
|
||||
static noop = new ApiClient({ baseUrl: "" })
|
||||
|
||||
constructor({
|
||||
baseUrl,
|
||||
middlewares = [],
|
||||
}: {
|
||||
baseUrl: string
|
||||
middlewares?: ApiRequestMiddleware[]
|
||||
}) {
|
||||
this.baseUrl = baseUrl
|
||||
this.middlewares = middlewares
|
||||
}
|
||||
|
||||
async request<T>(...[url, init = {}]: Parameters<typeof fetch>): Promise<[Response, T]> {
|
||||
const finalInit = this.middlewares.reduce(
|
||||
(prevInit, middleware) => middleware(url, prevInit),
|
||||
init,
|
||||
)
|
||||
return fetch(this.baseUrl ? new URL(url.toString(), this.baseUrl) : url, finalInit).then((res) =>
|
||||
Promise.all([Promise.resolve(res), res.json()]),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export const ApiClientContext = createContext(ApiClient.noop)
|
||||
export function useApiClient() {
|
||||
return useContext(ApiClientContext)
|
||||
}
|
||||
@@ -1,17 +1,29 @@
|
||||
import "react-native-reanimated"
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
|
||||
import { Stack } from "expo-router"
|
||||
import { StatusBar } from "expo-status-bar"
|
||||
import React from "react"
|
||||
import { useColorScheme } from "react-native"
|
||||
import tw, { useDeviceContext } from "twrnc"
|
||||
|
||||
import { authMiddleware } from "@/api/auth-middleware"
|
||||
import { ApiClient, ApiClientContext } from "@/api/client"
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
const apiClient = new ApiClient({
|
||||
baseUrl: process.env.EXPO_PUBLIC_API_BASE_URL ?? "",
|
||||
middlewares: [authMiddleware],
|
||||
})
|
||||
|
||||
export default function RootLayout() {
|
||||
useDeviceContext(tw)
|
||||
|
||||
const colorScheme = useColorScheme()
|
||||
const headerBg = colorScheme === "dark" ? "#1c1917" : "#f5f5f4"
|
||||
const headerTint = colorScheme === "dark" ? "#e7e5e4" : "#1c1917"
|
||||
|
||||
return (
|
||||
<>
|
||||
<ContextProvider>
|
||||
<Stack
|
||||
screenOptions={{
|
||||
headerShown: false,
|
||||
@@ -40,6 +52,14 @@ export default function RootLayout() {
|
||||
/>
|
||||
</Stack>
|
||||
<StatusBar style="auto" />
|
||||
</>
|
||||
</ContextProvider>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextProvider({ children }: React.PropsWithChildren) {
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<ApiClientContext value={apiClient}>{children}</ApiClientContext>
|
||||
</QueryClientProvider>
|
||||
)
|
||||
}
|
||||
|
||||
13
apps/aelis-client/src/feed/queries.ts
Normal file
13
apps/aelis-client/src/feed/queries.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { queryOptions } from "@tanstack/react-query"
|
||||
|
||||
import { useApiClient } from "@/api/client"
|
||||
|
||||
import { FeedItem } from "./types"
|
||||
|
||||
export function useFeedQuery() {
|
||||
const api = useApiClient()
|
||||
return queryOptions({
|
||||
queryKey: ["feed"],
|
||||
queryFn: async () => api.request<{ items: FeedItem[] }>("/feed?render=json-render"),
|
||||
})
|
||||
}
|
||||
5
apps/aelis-client/src/feed/types.ts
Normal file
5
apps/aelis-client/src/feed/types.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Spec } from "@json-render/core"
|
||||
|
||||
export interface FeedItem {
|
||||
ui: Spec
|
||||
}
|
||||
5
bun.lock
5
bun.lock
@@ -46,6 +46,7 @@
|
||||
"@react-navigation/bottom-tabs": "^7.4.0",
|
||||
"@react-navigation/elements": "^2.6.3",
|
||||
"@react-navigation/native": "^7.1.8",
|
||||
"@tanstack/react-query": "^5.90.21",
|
||||
"expo": "~54.0.33",
|
||||
"expo-constants": "~18.0.13",
|
||||
"expo-dev-client": "~6.0.20",
|
||||
@@ -1189,6 +1190,10 @@
|
||||
|
||||
"@tailwindcss/vite": ["@tailwindcss/vite@4.2.1", "", { "dependencies": { "@tailwindcss/node": "4.2.1", "@tailwindcss/oxide": "4.2.1", "tailwindcss": "4.2.1" }, "peerDependencies": { "vite": "^5.2.0 || ^6 || ^7" } }, "sha512-TBf2sJjYeb28jD2U/OhwdW0bbOsxkWPwQ7SrqGf9sVcoYwZj7rkXljroBO9wKBut9XnmQLXanuDUeqQK0lGg/w=="],
|
||||
|
||||
"@tanstack/query-core": ["@tanstack/query-core@5.90.20", "", {}, "sha512-OMD2HLpNouXEfZJWcKeVKUgQ5n+n3A2JFmBaScpNDUqSrQSjiveC7dKMe53uJUg1nDG16ttFPz2xfilz6i2uVg=="],
|
||||
|
||||
"@tanstack/react-query": ["@tanstack/react-query@5.90.21", "", { "dependencies": { "@tanstack/query-core": "5.90.20" }, "peerDependencies": { "react": "^18 || ^19" } }, "sha512-0Lu6y5t+tvlTJMTO7oh5NSpJfpg/5D41LlThfepTixPYkJ0sE2Jj0m0f6yYqujBwIXlId87e234+MxG3D3g7kg=="],
|
||||
|
||||
"@tsconfig/node10": ["@tsconfig/node10@1.0.12", "", {}, "sha512-UCYBaeFvM11aU2y3YPZ//O5Rhj+xKyzy7mvcIoAjASbigy8mHMryP5cK7dgjlz2hWxh1g5pLw084E0a/wlUSFQ=="],
|
||||
|
||||
"@tsconfig/node12": ["@tsconfig/node12@1.0.11", "", {}, "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag=="],
|
||||
|
||||
Reference in New Issue
Block a user