Skip to content

Commit

Permalink
Create a seam for changing how the about-us page is loaded
Browse files Browse the repository at this point in the history
Refs #2186
  • Loading branch information
thewilkybarkid committed Jan 17, 2025
1 parent 7fb90aa commit 794e3d2
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/GhostPage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FetchHttpClient } from '@effect/platform'
import { Context, Data, Effect, flow, Layer, Match } from 'effect'
import { Context, Data, Effect, flow, Layer, Match, pipe } from 'effect'
import * as R from 'fp-ts/lib/Reader.js'
import type * as TE from 'fp-ts/lib/TaskEither.js'
import * as FptsToEffect from './FptsToEffect.js'
Expand Down Expand Up @@ -27,20 +27,26 @@ export const layer = Layer.effect(
Effect.gen(function* () {
const fetch = yield* FetchHttpClient.Fetch
const ghostApi = yield* GhostApi
return flow(
id =>
FptsToEffect.readerTaskEither(getPage(id), {
fetch,
ghostApi,
return id =>
pipe(
Effect.if(id === '6154aa157741400e8722bb14', {
onTrue: () => Effect.log('Loading about-us page'),
onFalse: () => Effect.void,
}),
Effect.mapError(
flow(
Match.value,
Match.when('not-found', () => new PageIsNotFound()),
Match.when('unavailable', () => new PageIsUnavailable()),
Match.exhaustive,
Effect.andThen(
FptsToEffect.readerTaskEither(getPage(id), {
fetch,
ghostApi,
}),
),
),
)
Effect.mapError(
flow(
Match.value,
Match.when('not-found', () => new PageIsNotFound()),
Match.when('unavailable', () => new PageIsUnavailable()),
Match.exhaustive,
),
),
)
}),
)

0 comments on commit 794e3d2

Please sign in to comment.