Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 19 additions & 1 deletion Mine/src/api/magazine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import type {
FeedDto,
PatchMagazineTitleDto,
PostMagazineDto,
RequestAddSection,
RequestAddSectionInSectionPage,
RequestDeleteMagazine,
ResponseAddSection,
ResponseAddSectionInSectionPage,
ResponseFeed,
ResponseRecentSection,
SectionDetailDto,
Expand Down Expand Up @@ -93,7 +97,21 @@ export const createMoodboard = async (magazineId: number) => {
return res.data
}

export const postAddSection = async ({ magazineId, message }: RequestAddSection): Promise<ResponseAddSection> => {
const res = await axiosInstance.post(`api/magazines/${magazineId}/interact`, { message })
return res.data
}

export const postAddSectionInSectionPage = async ({
magazineId,
sectionId,
message,
}: RequestAddSectionInSectionPage): Promise<ResponseAddSectionInSectionPage> => {
const res = await axiosInstance.post(`api/magazines/${magazineId}/sections/${sectionId}/interact`, { message })
return res.data
}

export const patchMagazineCover = async (id: number, coverImageUrl: string) => {
const res = await axiosInstance.patch(`api/magazines/${id}/cover`, { coverImageUrl })
return res.data
}
}
6 changes: 3 additions & 3 deletions Mine/src/components/LLMInputBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function LLMInputBox({ onSend }: LLMInputBoxProps) {

return (
<div
className={`relative mx-auto flex items-end transition-all duration-300 ease-in-out w-192.5 min-h-13.5 bg-main-light border py-3 px-7 gap-10 ${isFocused ? 'border-main-default opacity-100' : 'border-main-opacity50 opacity-40'} ${isExpanded ? 'rounded-4xl ' : 'rounded-full'}`}
className={`relative mx-auto flex items-end transition-all duration-300 ease-in-out w-192.5 min-h-13.5 bg-gray-100-op90 border-gray-500 border py-3 px-3 gap-10 ${isFocused ? ' ' : 'opacity-40'} ${isExpanded ? 'rounded-4xl ' : 'rounded-full'}`}
>
<textarea
ref={textareaRef}
Expand All @@ -51,7 +51,7 @@ export default function LLMInputBox({ onSend }: LLMInputBoxProps) {
onBlur={() => setIsFocused(false)}
onKeyDown={handleKeyDown}
placeholder="관심있는 주제를 입력해 주세요."
className="mb-1 w-full min-h-6 resize-none bg-transparent font-regular16 leading-normal text-black-textBigTitle outline-none placeholder-black-textInTheBox overflow-y-auto"
className="mb-1 ml-4 w-full min-h-6 resize-none font-regular16 leading-normal text-gray-600 outline-none placeholder-gray-500-op40 overflow-y-auto"
style={{
scrollbarWidth: 'none',
msOverflowStyle: 'none',
Expand All @@ -61,7 +61,7 @@ export default function LLMInputBox({ onSend }: LLMInputBoxProps) {
<button
onClick={handleSend}
disabled={!text.trim()}
className={`flex shrink-0 w-7.5 h-7.5 rounded-full p-1.25 focus-within:bg-main-default bg-main-opacity50 items-center justify-center transition-colors duration-200 ${!isExpanded && 'mb-0.5'}
className={`flex shrink-0 w-7.5 h-7.5 rounded-full p-1.25 bg-gray-500 items-center justify-center transition-colors duration-200 ${!isExpanded && 'mb-0.5'}
`}
>
<Arrow />
Expand Down
57 changes: 50 additions & 7 deletions Mine/src/components/LLMInputLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
import { useLocation } from 'react-router-dom'
import { matchPath, useLocation } from 'react-router-dom'
import LLMInputBox from './LLMInputBox'
import usePostAddSection from '../hooks/usePostAddSection'
import usePostAddSectionInSectionPage from '../hooks/usePostAddSectionInSectionPage'
import usePostMagazine from '../hooks/usePostMagazine'
import { useAuthStore } from '../stores/auth'

export default function LLMInputLayout() {
const { isLoggedIn } = useAuthStore()
const location = useLocation()
const hiddenPath = ['/login', '/signup', '/landing', '/']
const isHiddenPath = hiddenPath.includes(location.pathname)

if (!isHiddenPath)
return (
<div className="absolute bottom-8 translate-x-1/2">
<LLMInputBox />
const postAddSectionMutation = usePostAddSection()
const postAddInSectionPageMutation = usePostAddSectionInSectionPage()
const postMagazineMutation = usePostMagazine()

const sectionMatch = matchPath('/magazine/:magazineId/section/:sectionId', location.pathname)
const magazineMatch = matchPath('/magazine/:magazineId', location.pathname)

const currentMagazineId = magazineMatch?.params.magazineId

const isNumericMagazineId = currentMagazineId && !isNaN(Number(currentMagazineId))

if (!isLoggedIn || isHiddenPath) return null

const handleSend = (value: string) => {
if (sectionMatch) {
// 섹션 페이지
const { magazineId, sectionId } = sectionMatch.params
postAddInSectionPageMutation.mutate({
magazineId: Number(magazineId),
sectionId: Number(sectionId),
message: value,
})
} else if (magazineMatch && isNumericMagazineId) {
// 매거진 페이지
const { magazineId } = magazineMatch.params
postAddSectionMutation.mutate({
magazineId: Number(magazineId),
message: value,
})
} else {
// 그외 페이지
postMagazineMutation.mutate({
topic: value,
user_mood: '',
})
}
}

return (
<div className="fixed bottom-8 left-0 w-full flex justify-center z-50 pointer-events-none">
<div className="pointer-events-auto">
<LLMInputBox onSend={handleSend} />
</div>
)
return null
</div>
)
}
16 changes: 16 additions & 0 deletions Mine/src/hooks/usePostAddSection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { postAddSection } from '../api/magazine'

export default function usePostAddSection() {
const queryClient = useQueryClient()
return useMutation({
mutationFn: postAddSection,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['mymagazines'] })
},
onError: (error) => {
console.log('섹션 생성:', error)
alert('섹션 생성에 실패했습니다.')

Choose a reason for hiding this comment

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

high

alert()는 사용자의 흐름을 방해하고 좋지 않은 사용자 경험을 제공할 수 있습니다. 에러 메시지를 표시하기 위해 토스트 UI 컴포넌트나 페이지 내 메시지 영역을 사용하는 것을 고려해 보세요. 이는 사용자에게 더 나은 피드백을 제공하고 애플리케이션의 일관성을 유지하는 데 도움이 됩니다.

References
  1. Using a consistent toast message for user feedback, especially for error messages, aligns with providing a better and more consistent user experience across different actions within the same conceptual flow.

},
})
}
16 changes: 16 additions & 0 deletions Mine/src/hooks/usePostAddSectionInSectionPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { postAddSectionInSectionPage } from '../api/magazine'

export default function usePostAddSectionInSectionPage() {
const queryClient = useQueryClient()
return useMutation({
mutationFn: postAddSectionInSectionPage,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['mymagazines', 'sections'] })
},
onError: (error) => {
console.log('섹션 생성:', error)
alert('섹션 생성에 실패했습니다.')

Choose a reason for hiding this comment

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

high

alert()는 사용자의 흐름을 방해하고 좋지 않은 사용자 경험을 제공할 수 있습니다. 에러 메시지를 표시하기 위해 토스트 UI 컴포넌트나 페이지 내 메시지 영역을 사용하는 것을 고려해 보세요. 이는 사용자에게 더 나은 피드백을 제공하고 애플리케이션의 일관성을 유지하는 데 도움이 됩니다.

References
  1. Using a consistent toast message for user feedback, especially for error messages, aligns with providing a better and more consistent user experience across different actions within the same conceptual flow.

},
})
}
1 change: 1 addition & 0 deletions Mine/src/style/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
--color-gray-100-op30: #ffffff4d;
--color-gray-100-op40: #ffffff66;
--color-gray-100-op70: #ffffffb3;
--color-gray-100-op90: #ffffffe6;

--color-gray-300-op70: #a9a9a9b3;

Expand Down
28 changes: 27 additions & 1 deletion Mine/src/types/magazine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,30 @@ export type ResponseFeed = {
content: Magazine[]
nextCursor: number
hasNext: boolean
}
}

export type RequestAddSection = {
magazineId: number
message: string
}

export type RequestAddSectionInSectionPage = {
magazineId: number
sectionId: number
message: string
}
export type ResponseAddSection = {
message: string
actionType: string
section: {
heading: string
paragraphs: Paragraph[]
sectionId: number
thumbnailUrl: string
layoutType: string
layoutHint: string
displayOrder: number
}
}

export type ResponseAddSectionInSectionPage = ResponseAddSection
3 changes: 1 addition & 2 deletions Mine/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://52.63.142.228:8080',
target: 'https://api.minelover.com',
changeOrigin: true,
},
},
},
})

Loading