Skip to content

Commit

Permalink
chore: move some popover component styles to its file
Browse files Browse the repository at this point in the history
  • Loading branch information
orlinmalkja committed Jan 31, 2025
1 parent 2b5cefa commit f7ad3f4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 56 deletions.
8 changes: 2 additions & 6 deletions src/components/LocalTreeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ interface LocalTreeProps {

const LocalTreeModal: FC<LocalTreeProps> = ({ TriggerButton }) => {

// TODO: add a [loading, setLoading] => which shows the pop over when the tree has been loaded -> TreeView Component updates the loading of its parent

// function of this component: create a new Panel


return <div className="local-tree-modal">
<Popover>
<PopoverTrigger className="open-tree-button t-h-8 t-w-10 t-relative">
<PopoverTrigger>
{TriggerButton}
</PopoverTrigger>
<PopoverContent className="t-bg-white t-absolute t-z-10">
<PopoverContent>
<ContentModal/>
</PopoverContent>
</Popover>
Expand Down
20 changes: 10 additions & 10 deletions src/components/ui/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ const PopoverContent = React.forwardRef<
React.ElementRef<typeof PopoverPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
>(({ className, align = 'center', sideOffset = 4, ...props }, ref) => (
<PopoverPrimitive.Content
ref={ref}
align={align}
sideOffset={sideOffset}
className={cn(
'z-50 w-72 rounded-md border border-gray-200 bg-white p-4 text-gray-950 shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-gray-800 dark:bg-gray-950 dark:text-gray-50',
className
)}
{...props}
/>
<PopoverPrimitive.Content
ref={ref}
align={align}
sideOffset={sideOffset}
className={cn(
't-z-50 t-absolute t-bg-white w-72 rounded-md border border-gray-200 bg-white p-4 text-gray-950 shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-gray-800 dark:bg-gray-950 dark:text-gray-50',
className
)}
{...props}
/>
))
PopoverContent.displayName = PopoverPrimitive.Content.displayName
const ClosePopover = PopoverPrimitive.Close
Expand Down
71 changes: 31 additions & 40 deletions src/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,42 @@ const BLOB_CONTENT_TYPES = ['application/pdf', 'image/png', 'image/jpeg', 'audio
const TEXT_CONTENT_TYPES = ['text/xhtml+xml', 'text/plain', 'text/html', 'text/css']

export async function request<T>(url: string): Promise<HttpResponse<T>> {
try {
const response = await fetch(url)
if (!response.ok) {
return createErrorResponse(
'Error while loading data from this url ' + url,
response.status
)
}

const contentType = response.headers.get('Content-Type')
let data
if (!contentType || TEXT_CONTENT_TYPES.some(type => contentType.includes(type))) {
data = await response.text()
} else if (contentType.includes('application/json')) {
data = await response.json()
} else if (BLOB_CONTENT_TYPES.some(type => contentType.includes(type))) {
data = await response.blob()
}
try {
const response = await fetch(url)
if (!response.ok) {
return createErrorResponse(
'Error while loading data from this url ' + url,
response.status
)
}

return {
success: true,
data
}
} catch (error) {
return createErrorResponse(
(error instanceof Error) ? error.message : 'An unexpected error occurred',
500,
)
const contentType = response.headers.get('Content-Type')
let data
if (!contentType || TEXT_CONTENT_TYPES.some(type => contentType.includes(type))) {
data = await response.text()
} else if (contentType.includes('application/json')) {
data = await response.json()
} else if (BLOB_CONTENT_TYPES.some(type => contentType.includes(type))) {
data = await response.blob()
}
}

function createErrorResponse(message: string = '', code: number = 500): ErrorResponse {
return {
success: false,
message,
code,
success: true,
data
}
} catch (error) {
return createErrorResponse(
(error instanceof Error) ? error.message : 'An unexpected error occurred',
500,
)
}
}

export function isValidUrl(value: string) {
try {
new URL(value) // Try to create a new URL object
return true // If no error occurs, it's a valid URL
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
return false // If an error occurs, it's not a valid URL
}
function createErrorResponse(message: string = '', code: number = 500): ErrorResponse {
return {
success: false,
message,
code,
}
}

0 comments on commit f7ad3f4

Please sign in to comment.