Skip to content

Commit

Permalink
Merge pull request #40 from DimensionDev/feat/custom-font
Browse files Browse the repository at this point in the history
  • Loading branch information
guanbinrui authored Sep 25, 2024
2 parents 8491a25 + dfc4e94 commit 683b3f2
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 114 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@vercel/kv": "^1.0.1",
"autoprefixer": "10.4.16",
"clsx": "^2.1.0",
"frames.js": "^0.16.4",
"frames.js": "^0.19.3",
"geist": "^1.2.1",
"http-status-codes": "^2.3.0",
"next": "latest",
Expand Down
127 changes: 92 additions & 35 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added public/Inter-Bold.ttf
Binary file not shown.
Binary file added public/Inter-Regular.ttf
Binary file not shown.
Binary file added public/checked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/selected.png
Binary file not shown.
18 changes: 10 additions & 8 deletions src/components/PollCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ function VoteResult({ choice, theme, isMax }: VoteResultProps) {
backgroundColor: theme.optionBgColor,
borderRadius: 12 * IMAGE_ZOOM_SCALE,
fontSize: 20 * IMAGE_ZOOM_SCALE,
fontWeight: isMax ? 'bold' : 'normal',
fontFamily: 'Inter',
fontWeight: isMax ? 700 : 400,
color: theme.secondTextColor,
overflow: 'hidden',
}}
Expand Down Expand Up @@ -107,7 +108,7 @@ function VoteResult({ choice, theme, isMax }: VoteResultProps) {
style={{
display: 'flex',
alignItems: 'center',
width: '86%',
width: choice.is_select ? '80%' : '86%',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
Expand All @@ -117,10 +118,10 @@ function VoteResult({ choice, theme, isMax }: VoteResultProps) {
<img
alt="selected"
style={{
width: 24 * IMAGE_ZOOM_SCALE,
height: 24 * IMAGE_ZOOM_SCALE,
marginRight: 4 * IMAGE_ZOOM_SCALE,
width: 16 * IMAGE_ZOOM_SCALE,
}}
src={`${env.external.NEXT_PUBLIC_HOST}/selected.png`}
src={`${env.external.NEXT_PUBLIC_HOST}/checked.png`}
/>
) : null}
{choice.name}
Expand Down Expand Up @@ -164,7 +165,7 @@ export function PollCard({ poll, locale, profileId }: PollCardProps) {
<div
style={{
display: 'flex',
marginTop: 138 * IMAGE_ZOOM_SCALE,
marginTop: 150 * IMAGE_ZOOM_SCALE,
justifyContent: 'center',
width: '100%',
fontSize: 24 * IMAGE_ZOOM_SCALE,
Expand All @@ -183,7 +184,6 @@ export function PollCard({ poll, locale, profileId }: PollCardProps) {
width: '100%',
color: themeConfig.secondTextColor,
fontSize: 28 * IMAGE_ZOOM_SCALE,
fontWeight: 'bold',
textAlign: 'center',
}}
>
Expand All @@ -196,6 +196,8 @@ export function PollCard({ poll, locale, profileId }: PollCardProps) {
textOverflow: 'ellipsis',
wordBreak: 'break-word',
maxWidth: '100%',
fontFamily: 'Inter',
fontWeight: 700,
}}
>
{poll.title}
Expand Down Expand Up @@ -230,7 +232,7 @@ export function PollCard({ poll, locale, profileId }: PollCardProps) {
flexDirection: 'column',
width: '100%',
gap: 8 * IMAGE_ZOOM_SCALE,
padding: `0 ${83 * IMAGE_ZOOM_SCALE}px`,
padding: `0 ${(showResult ? 83 : 50) * IMAGE_ZOOM_SCALE}px`,
}}
>
{choice_detail.map((choice, index) => {
Expand Down
12 changes: 9 additions & 3 deletions src/config/frames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createFrames } from 'frames.js/next';

import { lensFrame } from '@/config/lensFrame';
import { env } from '@/constants/env';
import { loadFonts } from '@/helpers/loadFonts';
import { FrameContext } from '@/types';

const hubRequestHeaders: Record<string, string> = {};
Expand All @@ -15,9 +16,7 @@ export const frames = createFrames({
baseUrl: env.external.NEXT_PUBLIC_HOST,
basePath: '/api/frames',
middleware: [
imagesWorkerMiddleware({
imagesRoute: '/images',
}),
imagesWorkerMiddleware({}),
farcasterHubContext({
hubHttpUrl: env.external.NEXT_PUBLIC_HUB_URL,
hubRequestOptions: {
Expand All @@ -26,6 +25,13 @@ export const frames = createFrames({
}),
lensFrame,
],
imageRenderingOptions: async () => {
const fonts = await loadFonts();

return {
imageOptions: { fonts },
};
},
});

export type FrameHandler = (ctx: FrameContext) => ReturnType<Parameters<typeof frames>[0]>;
8 changes: 3 additions & 5 deletions src/config/lensFrame.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { getLensFrameMessage, isLensFrameActionPayload } from 'frames.js/lens';
import { openframes } from 'frames.js/middleware';

import { getLensFrameMessage } from '@/helpers/getLensFrameMessage';
import { isLensFrameActionPayload } from '@/helpers/isLensFrameActionPayload';

export const lensFrame = openframes({
clientProtocol: {
id: 'lens',
version: '1.0.0',
},
handler: {
isValidPayload: (body: JSON) => isLensFrameActionPayload(body),
getFrameMessage: async (body: JSON) => {
isValidPayload: (body) => isLensFrameActionPayload(body),
getFrameMessage: async (body) => {
if (!isLensFrameActionPayload(body)) return;
const result = await getLensFrameMessage(body);

Expand Down
Loading

0 comments on commit 683b3f2

Please sign in to comment.