Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Search and Profile Frontend #62

Merged
merged 61 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f1e381e
remove unused code
saifullah-talukder Jun 13, 2024
7acf61a
use appropriate svg property name in react
saifullah-talukder Jun 13, 2024
ec20f5f
implement error handling (prevent app from crashing when no data is f…
saifullah-talukder Jun 13, 2024
eb198d9
remove unused context
saifullah-talukder Jun 13, 2024
dc90d06
handle automatic signout whenever 405 status code received from backend
saifullah-talukder Jun 13, 2024
cdaed6c
add search result and thread component file
saifullah-talukder Jun 13, 2024
84026e8
Merge branch 'eng-184' into eng-190
saifullah-talukder Jun 13, 2024
64fcb7b
Merge branch 'eng-179' into eng-190
saifullah-talukder Jun 14, 2024
50ce615
temp stash
saifullah-talukder Jun 18, 2024
3ca997f
Merge branch 'develop' into eng-190
saifullah-talukder Jun 18, 2024
cddf923
thread page implemented
saifullah-talukder Jun 19, 2024
1835110
update source menu height calculation
saifullah-talukder Jun 19, 2024
a1d15ac
implement streaming response
saifullah-talukder Jun 20, 2024
bc43474
implement thread history
saifullah-talukder Jun 20, 2024
903f71d
remove unnecessary code
saifullah-talukder Jun 20, 2024
838730a
bug fix in search history navigation
saifullah-talukder Jun 20, 2024
b4cf36e
source menu style fix
saifullah-talukder Jun 20, 2024
6b7b3f1
frontend stash (working on profile page)
saifullah-talukder Jun 20, 2024
e64c400
Merge branch 'develop' into eng-190
saifullah-talukder Jun 20, 2024
d5335f4
implement proxy api for streaming
saifullah-talukder Jun 24, 2024
a02b084
design fix in streaming response component
saifullah-talukder Jun 24, 2024
79f43b6
implement profile settings UI
saifullah-talukder Jun 24, 2024
c0a57a1
integrate profile update api
saifullah-talukder Jun 24, 2024
4032a8e
remove unsued code
saifullah-talukder Jun 24, 2024
67de95a
implement email edit functionality
saifullah-talukder Jun 24, 2024
afbcb13
implement update password design
saifullah-talukder Jun 24, 2024
a9089f0
implement update password
saifullah-talukder Jun 24, 2024
24a4a7b
Merge branch 'eng-179' into eng-190
saifullah-talukder Jun 25, 2024
0bc64bf
remove console logs
saifullah-talukder Jun 25, 2024
805ce6f
Merge branch 'develop' into eng-190
saifullah-talukder Jun 25, 2024
1377e4a
adjust the parameters for rephrasing query
saifullah-talukder Jun 25, 2024
df29c7c
remove unnecessary code
saifullah-talukder Jun 25, 2024
9904f6b
adjust the logic on splitting respinse by new line
saifullah-talukder Jun 25, 2024
2b6dcef
fix bug in thread and streaming response UI
saifullah-talukder Jun 25, 2024
606ce06
adjust fade in time for search response
saifullah-talukder Jun 25, 2024
ac9dbd1
improve design for streaming response
saifullah-talukder Jun 25, 2024
62edfce
implement viewing source description using backend provided HTML
saifullah-talukder Jun 25, 2024
50ff8a9
add two new env variables for deployment
saifullah-talukder Jun 25, 2024
193098e
Merge branch 'develop' into eng-190
saifullah-talukder Jun 25, 2024
6c98cee
add new env for server deployment
saifullah-talukder Jun 25, 2024
c8c13db
resolve potential risk of having \n in response
saifullah-talukder Jun 25, 2024
876dd05
implement properly setting the content encoding header
saifullah-talukder Jun 25, 2024
dd4846f
refactoring: improve code readability for stream response splitting
saifullah-talukder Jun 25, 2024
15dadc1
indentation related bug fix in makefile_ecr
saifullah-talukder Jun 25, 2024
c41d0bc
add sqlx prepared queries
saifullah-talukder Jun 25, 2024
ea31473
update server readme to add instructions related to adding sqlx query
saifullah-talukder Jun 25, 2024
891ec4e
update agency values in helm
saifullah-talukder Jun 25, 2024
598a141
Update deployment.yaml
AsmiKloud Jun 25, 2024
acee6ac
Merge pull request #65 from curieo-org/search-server-deployment-issue…
rathijitpapon Jun 25, 2024
c3b4ba5
hide refresh button in search response
saifullah-talukder Jun 25, 2024
9696baa
hide thread title
saifullah-talukder Jun 26, 2024
5937c2f
unhide search title. (only thread title should be hidden)
saifullah-talukder Jun 26, 2024
9f486c5
Update service.yaml
AsmiKloud Jun 26, 2024
be83004
Update deployment.yaml
AsmiKloud Jun 26, 2024
87c21f9
Merge pull request #67 from curieo-org/eng-190-patch-for-helmchart
rathijitpapon Jun 26, 2024
85cbc94
Update virtualservice.yaml
AsmiKloud Jun 26, 2024
da61e70
Update deployment.yaml
AsmiKloud Jun 26, 2024
6002582
:construction: fix the dockerfile ca-certificate issue
rathijitpapon Jun 26, 2024
4aa63cb
:construction: fix the cluster json parsing issue
rathijitpapon Jun 26, 2024
8a4e194
:bug: fix linting
rathijitpapon Jun 26, 2024
87a8a50
resolve stream data splitting issue
saifullah-talukder Jun 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions agency/Makefile_ECR
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Image = curieo-agency
ECR = 698471419283.dkr.ecr.eu-central-1.amazonaws.com/curieo-agency
TAG = 2.0
TAG = 3.0

ecr_deploy: login
docker buildx build --platform linux/amd64 -t $(Image) .
docker buildx build --platform linux/amd64 -t $(Image) .
docker tag $(Image) $(ECR):$(TAG)
docker push $(ECR):$(TAG)
docker push $(ECR):$(TAG)

login:
aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 698471419283.dkr.ecr.eu-central-1.amazonaws.com
aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 698471419283.dkr.ecr.eu-central-1.amazonaws.com
22 changes: 22 additions & 0 deletions frontend/package-lock.json

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

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@auth/core": "^0.32.0",
"@tanstack/react-query": "^5.37.1",
"date-fns": "^3.6.0",
"dompurify": "^3.1.5",
"lodash": "^4.17.21",
"next": "^14.2.3",
"next-auth": "^5.0.0-beta.19",
Expand All @@ -27,6 +28,7 @@
"zustand": "^4.5.2"
},
"devDependencies": {
"@types/dompurify": "^3.0.5",
"@types/lodash": "^4.17.4",
"@types/node": "^20",
"@types/react": "^18",
Expand Down
44 changes: 44 additions & 0 deletions frontend/public/images/answer-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion frontend/src/actions/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { signOut } from '@/auth'
import { headers as next_headers } from 'next/headers'

function curieoApiUrl(reqInfo?: RequestInfo): URL {
Expand Down Expand Up @@ -36,6 +37,13 @@ export async function curieoFetch(reqInfo: RequestInfo, init?: RequestInit): Pro
} else {
init = { headers }
}

const url: URL = curieoApiUrl(reqInfo)
return fetch(url, init)
const response = await fetch(url, init)

if (response.status === 405) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's something we need to fix both in the backend and the frontend.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this resolved?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not till now. Working on it in a separate PR.

await signOut()
}

return response.ok ? Promise.resolve(response) : Promise.reject(response)
}
32 changes: 19 additions & 13 deletions frontend/src/actions/search.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
'use server'

import { SearchReactionBody, SearchResult } from '@/types/search'
import { curieoFetch } from '@/actions/fetch'

export async function search(query: string): Promise<SearchResult> {
const response = await curieoFetch(`/search?${new URLSearchParams({ query })}`)
if (response.ok) {
return (await response.json()) as SearchResult
}
throw new Error('Search failed')
}
import { SearchHistoryResponse, SearchReactionBody, SearchResult, ThreadByIdResponse } from '@/types/search'

export async function searchById(id: string): Promise<SearchResult> {
const response = await curieoFetch(`/search/one?search_history_id=${id}`)
Expand All @@ -19,21 +11,35 @@ export async function searchById(id: string): Promise<SearchResult> {
throw new Error('Retrieving search failed')
}

export async function searchHistory({ limit, offset }: { limit: number; offset: number }): Promise<SearchResult[]> {
export async function searchHistory({
limit,
offset,
}: {
limit: number
offset: number
}): Promise<SearchHistoryResponse> {
const response = await curieoFetch(`/search/history?limit=${limit ?? 10}${offset ? `&offset=${offset}` : ``}`)
if (response.ok) {
return (await response.json()) as SearchResult[]
return (await response.json()) as SearchHistoryResponse
}
throw new Error('Retrieving search history failed')
}

export async function searchReaction(reaction: SearchReactionBody): Promise<SearchResult> {
export async function searchReaction(reaction: SearchReactionBody): Promise<void> {
const response = await curieoFetch('/search/reaction', {
method: 'PATCH',
body: JSON.stringify(reaction),
})
if (response.ok) {
return (await response.json()) as SearchResult
return
}
throw new Error('Could not submit reaction')
}

export async function threadById(id: string): Promise<ThreadByIdResponse> {
const response = await curieoFetch(`/search/threads?thread_id=${id}`)
if (response.ok) {
return (await response.json()) as ThreadByIdResponse
}
throw new Error('Retrieving search failed')
}
38 changes: 38 additions & 0 deletions frontend/src/actions/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use server'

import { UpdatePasswordBody, UpdateProfileBody, UserProfile } from '@/types/settings'
import { encodeAsUrlSearchParams } from '@/utils'
import { curieoFetch } from './fetch'

export async function fetchUserProfile(): Promise<UserProfile> {
const response = await curieoFetch('/users/me')
if (response.ok) {
return (await response.json()) as UserProfile
}
throw new Error('Could not retrieve user profile')
}

export async function updateUserProfile(payload: UpdateProfileBody): Promise<UserProfile> {
const response = await curieoFetch('/users/me', {
method: 'PATCH',
body: JSON.stringify(payload),
})
if (response.ok) {
return (await response.json()) as UserProfile
}
throw new Error('Could not update user profile')
}

export async function updatePassword(payload: UpdatePasswordBody): Promise<void> {
const response = await curieoFetch('/users/update-password', {
method: 'PATCH',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: encodeAsUrlSearchParams(payload),
})
if (response.ok) {
return
}
throw new Error('Could not update password')
}
47 changes: 47 additions & 0 deletions frontend/src/app/api/search/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { curieoFetch } from '@/actions/fetch'
import { NextRequest, NextResponse } from 'next/server'

export const GET = async (req: NextRequest) => {
const { searchParams } = new URL(req.url)
const searchQuery = searchParams.get('searchQuery')
const threadId = searchParams.get('threadId')

if (!searchQuery) {
return NextResponse.json({ error: 'searchQuery is required' }, { status: 400 })
}

async function pump(reader: ReadableStreamDefaultReader<Uint8Array>, writer: WritableStreamDefaultWriter<any>) {
while (true) {
const { done, value } = await reader.read()
if (done) break
writer.write(value)
}
writer.close()
}

try {
const response = await curieoFetch(`/search?query=${searchQuery}${threadId ? `&thread_id=${threadId}` : ``}`)

if (!response.ok) {
return NextResponse.json({ error: 'Failed to fetch data from external API' }, { status: response.status })
}

const reader = response.body?.getReader()
if (!reader) {
return NextResponse.json({ error: 'Failed to read from external API stream' }, { status: 500 })
}

const headers = new Headers(response.headers)
headers.delete('content-encoding')
headers.set('content-encoding', 'none')
ivarflakstad marked this conversation as resolved.
Show resolved Hide resolved

const { readable, writable } = new TransformStream()
const writer = writable.getWriter()

pump(reader!, writer).catch(err => err)

return new NextResponse(readable, { headers })
} catch (error) {
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
}
}
6 changes: 3 additions & 3 deletions frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import Providers from '@/components/wrappers/providers'
import { appDescription, appTitle } from '@/constants/app'
import '@/styles/globals.css'
import type { Metadata } from 'next'
import { Onest } from 'next/font/google'
import { Manrope } from 'next/font/google'
import { ReactNode } from 'react'
import 'react-toastify/dist/ReactToastify.css'

const onest = Onest({ subsets: ['latin'] })
const manrope = Manrope({ subsets: ['latin'] })

export const metadata: Metadata = {
title: appTitle,
Expand All @@ -25,7 +25,7 @@ export default async function RootLayout({ children }: LayoutProps) {
<link rel="icon" type="image/x-icon" href="/images/curieo-logo.svg" />
<title>Curieo Search</title>
</head>
<body className={onest.className} suppressHydrationWarning={true}>
<body className={manrope.className} suppressHydrationWarning={true}>
<Providers>
<App>{children}</App>
</Providers>
Expand Down
76 changes: 0 additions & 76 deletions frontend/src/app/search/[searchHistoryId]/page.tsx

This file was deleted.

Loading