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
5 changes: 4 additions & 1 deletion moon/apps/web/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'

import { ThemeProvider } from '../components/Providers/ThemeProvider'
import { ScopeProvider } from '../contexts/scope'
import { QueryNormalizerProvider } from '../utils/normy/QueryNormalizerProvider'

const client = new QueryClient({})

Expand All @@ -20,7 +21,9 @@ const preview: Preview = {
<QueryClientProvider client={client}>
<ThemeProvider>
<ScopeProvider>
<Story />
<QueryNormalizerProvider queryClient={client}>
<Story />
</QueryNormalizerProvider>
</ScopeProvider>
</ThemeProvider>
</QueryClientProvider>
Expand Down
119 changes: 60 additions & 59 deletions moon/apps/web/components/CodeView/TreeView/CloneTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,69 +1,70 @@
import React, { useEffect, useState } from 'react';
import { Tabs, TabsProps, Button, Space, Popover, Input } from 'antd';
import copy from 'copy-to-clipboard';
import {CopyIcon, DownloadIcon} from '@gitmono/ui/Icons'
import { CheckOutlined, } from '@ant-design/icons';
import { usePathname } from 'next/navigation';
import React, { useEffect, useState } from 'react'
import { Button, Input, Popover, Space, Tabs, TabsProps } from 'antd'
import copy from 'copy-to-clipboard'
import { usePathname } from 'next/navigation'

import { CheckIcon, CopyIcon, DownloadIcon } from '@gitmono/ui/Icons'

const CloneTabs = ({ endpoint }:any) => {
const pathname = usePathname();
const [text, setText] = useState<string>(pathname||'');
const [copied, setCopied] = useState<boolean>(false);
const [active_tab, setActiveTab] = useState<string>('1')
const CloneTabs = ({ endpoint }: any) => {
const pathname = usePathname()
const [text, setText] = useState<string>(pathname || '')
const [copied, setCopied] = useState<boolean>(false)
const [active_tab, setActiveTab] = useState<string>('1')

const onChange = (key: string) => {
setActiveTab(key)
};
const onChange = (key: string) => {
setActiveTab(key)
}

useEffect(() => {
if (endpoint) {
const url = new URL(endpoint);
useEffect(() => {
if (endpoint) {
const url = new URL(endpoint)

if (active_tab === '1') {
setText(`${url.href}${pathname?.replace('/tree/', '')}.git`);
} else {
setText(`ssh://git@${url.host}${pathname?.replace('/tree', '')}.git`);
}
}
}, [pathname, active_tab, endpoint]);
if (active_tab === '1') {
setText(`${url.href}${pathname?.replace('/tree/', '')}.git`)
} else {
setText(`ssh://git@${url.host}${pathname?.replace('/tree', '')}.git`)
}
}
}, [pathname, active_tab, endpoint])

const handleCopy = () => {
copy(text)
setCopied(true)
setTimeout(() => setCopied(false), 2000) // Reset after 2 seconds
}

const tab_items: TabsProps['items'] = [
{
key: '1',
label: 'HTTP',
children: (
<Space style={{ width: '100%' }}>
<Input value={text} />
<Button onClick={handleCopy} icon={copied ? <CheckIcon /> : <CopyIcon />} size={'small'} />
</Space>
)
},
{
key: '2',
label: 'SSH',
children: (
<Space style={{ width: '100%' }}>
<Input value={text} />
<Button onClick={handleCopy} icon={copied ? <CheckIcon /> : <CopyIcon />} size={'small'} />
</Space>
)
}
]

const handleCopy = () => {
copy(text);
setCopied(true);
setTimeout(() => setCopied(false), 2000); // Reset after 2 seconds
};

const tab_items: TabsProps['items'] = [
{
key: '1',
label: 'HTTP',
children:
<Space style={{ width: '100%' }}>
<Input value={text} />
<Button onClick={handleCopy} icon={copied ? <CheckOutlined /> : <CopyIcon />} size={'small'} />
</Space>
},
{
key: '2',
label: 'SSH',
children: <Space style={{ width: '100%' }}>
<Input value={text} />
<Button onClick={handleCopy} icon={copied ? <CheckOutlined /> : <CopyIcon />} size={'small'} />
</Space>
}
];

return (
<Popover placement="bottomRight"
content={<Tabs defaultActiveKey="1" items={tab_items} onChange={onChange} />}
trigger="click">
<Button icon={<DownloadIcon />}>Code</Button>
</Popover>
)

return (
<Popover
placement='bottomRight'
content={<Tabs defaultActiveKey='1' items={tab_items} onChange={onChange} />}
trigger='click'
>
<Button icon={<DownloadIcon />}>Code</Button>
</Popover>
)
}

export default CloneTabs;
export default CloneTabs
Loading