Skip to content

Commit a4a0713

Browse files
chore: refactored StreamText Component
1 parent cf58633 commit a4a0713

File tree

9 files changed

+57
-11
lines changed

9 files changed

+57
-11
lines changed

app/(dashboard)/(routes)/preview-course/[courseId]/_components/preview-description.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { BookA, BookOpen, CalendarDays } from 'lucide-react';
66
import { useLocale, useTranslations } from 'next-intl';
77
import { useState } from 'react';
88

9-
import { GenerateTextResponseAi } from '@/components/ai/generate-text-response-ai';
9+
import { StreamText } from '@/components/ai/stream-text';
1010
import { IconBadge } from '@/components/common/icon-badge';
1111
import { Price } from '@/components/common/price';
1212
import { TextBadge } from '@/components/common/text-badge';
@@ -64,7 +64,7 @@ export const PreviewDescription = ({
6464
</div>
6565
{Boolean(user?.userId) && language !== currentLocale && (
6666
<div className="my-2">
67-
<GenerateTextResponseAi
67+
<StreamText
6868
cacheKey={`preview-course-description-[${id}]::user-[${user?.userId}]-[${currentLocale}]`}
6969
isTranslateButton
7070
callback={setTranslatedDescription}

app/(dashboard)/(routes)/teacher/courses/[courseId]/_components/form/description-form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useEffect, useState } from 'react';
88
import { useForm } from 'react-hook-form';
99
import * as z from 'zod';
1010

11-
import { GenerateTextResponseAi } from '@/components/ai/generate-text-response-ai';
11+
import { StreamText } from '@/components/ai/stream-text';
1212
import { Button } from '@/components/ui/button';
1313
import {
1414
Form,
@@ -80,7 +80,7 @@ export const DescriptionForm = ({ initialData, courseId }: DescriptionFormProps)
8080
Description
8181
<div className="flex items-center gap-x-2">
8282
{isEditing && (
83-
<GenerateTextResponseAi
83+
<StreamText
8484
callback={setNewDescription}
8585
isSubmitting={isSubmitting}
8686
isValid={isValid}

app/(dashboard)/(routes)/teacher/courses/[courseId]/chapters/[chapterId]/_components/form/chapter-description-form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Markdown from 'react-markdown';
1010
import ScrollToBottom from 'react-scroll-to-bottom';
1111
import * as z from 'zod';
1212

13-
import { GenerateTextResponseAi } from '@/components/ai/generate-text-response-ai';
13+
import { StreamText } from '@/components/ai/stream-text';
1414
import { CopyClipboard } from '@/components/common/copy-clipboard';
1515
import { Editor } from '@/components/common/editor';
1616
import { Preview } from '@/components/common/preview';
@@ -80,7 +80,7 @@ export const ChapterDescriptionForm = ({
8080
Description
8181
<div className="flex items-center gap-x-2">
8282
{isEditing && (
83-
<GenerateTextResponseAi
83+
<StreamText
8484
callback={setNewDescription}
8585
isSubmitting={isSubmitting}
8686
isValid={isValid}

app/api/users/network/route.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { geolocation, ipAddress } from '@vercel/functions';
2+
import { ReasonPhrases, StatusCodes } from 'http-status-codes';
3+
import { NextRequest, NextResponse } from 'next/server';
4+
5+
export const GET = async (req: NextRequest) => {
6+
try {
7+
const ip = ipAddress(req);
8+
const geo = geolocation(req);
9+
10+
return NextResponse.json({
11+
ip,
12+
...geo,
13+
});
14+
} catch (error) {
15+
console.error('[GET_USERS_NETWORK]', error);
16+
17+
return new NextResponse(ReasonPhrases.INTERNAL_SERVER_ERROR, {
18+
status: StatusCodes.INTERNAL_SERVER_ERROR,
19+
});
20+
}
21+
};

components/ai/generate-text-response-ai.tsx renamed to components/ai/stream-text.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { fetcher } from '@/lib/fetcher';
1313

1414
import { Button } from '../ui';
1515

16-
type GenerateTextResponseAiProps = {
16+
type StreamTextProps = {
1717
cacheKey?: string;
1818
callback: Dispatch<SetStateAction<string>>;
1919
isSubmitting?: boolean;
@@ -22,14 +22,14 @@ type GenerateTextResponseAiProps = {
2222
messages: { role: string; content: string }[];
2323
};
2424

25-
export const GenerateTextResponseAi = ({
25+
export const StreamText = ({
2626
cacheKey,
2727
callback,
2828
isSubmitting,
2929
isTranslateButton,
3030
isValid,
3131
messages,
32-
}: GenerateTextResponseAiProps) => {
32+
}: StreamTextProps) => {
3333
const t = useTranslations('ai-generate');
3434

3535
const { toast } = useToast();

components/common/preview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useMemo, useState } from 'react';
99
import { ChatCompletionRole, USER_TRANSLATE_PROMPT } from '@/constants/ai';
1010
import { useCurrentUser } from '@/hooks/use-current-user';
1111

12-
import { GenerateTextResponseAi } from '../ai/generate-text-response-ai';
12+
import { StreamText } from '../ai/stream-text';
1313

1414
type PreviewProps = {
1515
enableTranslate?: boolean;
@@ -30,7 +30,7 @@ export const Preview = ({ enableTranslate, id, language, value }: PreviewProps)
3030
<>
3131
{Boolean(user?.userId) && enableTranslate && language !== currentLocale && (
3232
<div className="p-4">
33-
<GenerateTextResponseAi
33+
<StreamText
3434
cacheKey={`preview-chapter-description-[${id}]::user-[${user?.userId}]-[${currentLocale}]`}
3535
isTranslateButton
3636
callback={setTranslatedDescription}

components/navbar/navbar-routes.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { SearchInput } from '@/components/common/search-input';
1212
import { Button, Skeleton } from '@/components/ui';
1313
import { AuthStatus } from '@/constants/auth';
1414
import { useCurrentUser } from '@/hooks/use-current-user';
15+
import { fetcher } from '@/lib/fetcher';
16+
import { isOwner } from '@/lib/owner';
1517

1618
import { Chat } from '../chat/chat';
1719
import { Notifications } from '../notifications/notifications';
@@ -84,6 +86,15 @@ export const NavBarRoutes = ({ globalProgress, userNotifications }: NavBarRoutes
8486
<Notifications userNotifications={userNotifications} />
8587
</>
8688
)}
89+
{isOwner(user?.userId) && (
90+
<button
91+
onClick={async () => {
92+
await fetcher.get('/api/users/network');
93+
}}
94+
>
95+
IP
96+
</button>
97+
)}
8798
<UserProfileButton globalProgress={globalProgress} />
8899
</div>
89100
)}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@tanstack/react-table": "^8.11.8",
4949
"@uploadthing/react": "^7.1.1",
5050
"@vercel/analytics": "^1.3.1",
51+
"@vercel/functions": "^2.1.0",
5152
"@vercel/kv": "^1.0.1",
5253
"@vercel/speed-insights": "^1.2.0",
5354
"@yandex/smart-captcha": "^2.6.0",

yarn.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3673,6 +3673,18 @@ __metadata:
36733673
languageName: node
36743674
linkType: hard
36753675

3676+
"@vercel/functions@npm:^2.1.0":
3677+
version: 2.1.0
3678+
resolution: "@vercel/functions@npm:2.1.0"
3679+
peerDependencies:
3680+
"@aws-sdk/credential-provider-web-identity": "*"
3681+
peerDependenciesMeta:
3682+
"@aws-sdk/credential-provider-web-identity":
3683+
optional: true
3684+
checksum: 10c0/6ff5a08439bc940d9409455f94e4caeca19c3528d429b25c4b479f3568c4bd8db6ed75c92d0a516ee71fd2ca6772dee7748032d553cf71a5b9b3cee7d9e0df72
3685+
languageName: node
3686+
linkType: hard
3687+
36763688
"@vercel/kv@npm:^1.0.1":
36773689
version: 1.0.1
36783690
resolution: "@vercel/kv@npm:1.0.1"
@@ -7886,6 +7898,7 @@ __metadata:
78867898
"@typescript-eslint/eslint-plugin": "npm:^6.20.0"
78877899
"@uploadthing/react": "npm:^7.1.1"
78887900
"@vercel/analytics": "npm:^1.3.1"
7901+
"@vercel/functions": "npm:^2.1.0"
78897902
"@vercel/kv": "npm:^1.0.1"
78907903
"@vercel/speed-insights": "npm:^1.2.0"
78917904
"@yandex/smart-captcha": "npm:^2.6.0"

0 commit comments

Comments
 (0)