generated from kevisual/vite-react-template
chore: update dependencies and improve configuration handling
- Bump version to 0.0.7 in package.json and update deployment script. - Add new dependencies in bun.lock for improved functionality. - Modify loadFromRemote methods in Gitea and general config stores to return boolean for better error handling. - Enhance BuildConfig component to ensure proper loading state management. - Simplify RepoCard component by removing duplicate repository access option. - Update WorkspaceDetailDialog to include workspace link in state management. - Fix branch default value in createDevConfig function to use a placeholder.
This commit is contained in:
@@ -54,7 +54,6 @@ export const useLayoutStore = create<LayoutStore>((set, get) => ({
|
||||
setMe: (me) => set({ me }),
|
||||
clearMe: () => {
|
||||
set({ me: undefined, isAdmin: false });
|
||||
window.location.href = '/root/login/?redirect=' + encodeURIComponent(window.location.href);
|
||||
},
|
||||
getMe: async () => {
|
||||
const res = await queryLogin.getMe();
|
||||
|
||||
@@ -8,7 +8,7 @@ type GiteaConfigState = {
|
||||
setConfig: (config: Partial<GiteaConfig>) => void;
|
||||
resetConfig: () => void;
|
||||
saveToRemote: () => Promise<void>;
|
||||
loadFromRemote: () => Promise<void>;
|
||||
loadFromRemote: () => Promise<boolean>;
|
||||
checkConfig: (opts?: { isUser?: boolean, reload?: boolean }) => Promise<boolean>;
|
||||
};
|
||||
|
||||
@@ -79,22 +79,24 @@ export const useGiteaConfigStore = create<GiteaConfigState>()((set, get) => ({
|
||||
})
|
||||
if (res.code === 404) {
|
||||
toast.error('远端配置不存在')
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (res.code === 200) {
|
||||
const config = res.data?.data as GiteaConfig;
|
||||
setConfig(config);
|
||||
toast.success('获取远端配置成功')
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
checkConfig: async (opts?: { isUser?: boolean, reload?: boolean }) => {
|
||||
const { GITEA_TOKEN } = get().config;
|
||||
if (!GITEA_TOKEN && opts?.isUser) {
|
||||
await get().loadFromRemote();
|
||||
if (opts?.reload) {
|
||||
const res = await get().loadFromRemote();
|
||||
if (opts?.reload && res) {
|
||||
location.reload();
|
||||
}
|
||||
return true
|
||||
return res;
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ type ConfigState = {
|
||||
setConfig: (config: Partial<Config>) => void;
|
||||
resetConfig: () => void;
|
||||
saveToRemote: () => Promise<void>;
|
||||
loadFromRemote: () => Promise<void>;
|
||||
loadFromRemote: () => Promise<boolean>;
|
||||
checkConfig: (opts?: { isUser?: boolean, reload?: boolean }) => Promise<boolean>;
|
||||
};
|
||||
|
||||
@@ -75,22 +75,24 @@ export const useConfigStore = create<ConfigState>()(
|
||||
})
|
||||
if (res.code === 404) {
|
||||
toast.error('远端配置不存在')
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (res.code === 200) {
|
||||
const config = res.data?.data as typeof config;
|
||||
setConfig(config);
|
||||
toast.success('获取远端配置成功')
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
checkConfig: async (opts?: { isUser?: boolean, reload?: boolean }) => {
|
||||
const { CNB_API_KEY } = get().config;
|
||||
if (!CNB_API_KEY && opts?.isUser) {
|
||||
await get().loadFromRemote();
|
||||
if (opts?.reload) {
|
||||
const res = await get().loadFromRemote();
|
||||
if (opts?.reload && res) {
|
||||
location.reload();
|
||||
}
|
||||
return true
|
||||
return res;
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -23,16 +23,20 @@ export const BuildConfig = () => {
|
||||
const navigate = useNavigate();
|
||||
const me = useLayoutStore((state) => state.me);
|
||||
const [localConfig, setLocalConfig] = useState(repoStore.buildConfig?.config || "");
|
||||
|
||||
const [mounted, setMounted] = useState(false);
|
||||
// 同步 buildConfig 变化时的状态
|
||||
useEffect(() => {
|
||||
setLocalConfig(repoStore.buildConfig?.config || "");
|
||||
}, [repoStore.buildConfig]);
|
||||
useEffect(() => {
|
||||
if (repo) {
|
||||
repoStore.initBuildConfig({ repo: repo, user: me });
|
||||
repoStore.initBuildConfig({ repo: repo, user: me }).then(() => {
|
||||
setMounted(true);
|
||||
});
|
||||
} else {
|
||||
setMounted(true);
|
||||
}
|
||||
}, [repo, me])
|
||||
}, [repo])
|
||||
|
||||
const handleSave = () => {
|
||||
if (repoStore.buildConfig) {
|
||||
@@ -51,7 +55,7 @@ export const BuildConfig = () => {
|
||||
}, false);
|
||||
}
|
||||
};
|
||||
if (repoStore.loading) {
|
||||
if (repoStore.loading || !mounted) {
|
||||
return <div>Loading...</div>
|
||||
}
|
||||
return (
|
||||
|
||||
@@ -190,6 +190,12 @@ export function RepoCard({ showReturn = false, repo }: RepoCardProps) {
|
||||
}
|
||||
/>
|
||||
<DropdownMenuContent align="end" className="w-40">
|
||||
<DropdownMenuItem onClick={() => {
|
||||
window.open(repo.web_url, '_blank')
|
||||
}} className="cursor-pointer">
|
||||
<ExternalLink className="w-4 h-4 mr-2" />
|
||||
访问仓库
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => {
|
||||
store.setEditRepo(repo)
|
||||
store.setShowEditDialog(true)
|
||||
@@ -222,12 +228,7 @@ export function RepoCard({ showReturn = false, repo }: RepoCardProps) {
|
||||
<Copy className="w-4 h-4 mr-2" />
|
||||
Clone URL
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => {
|
||||
window.open(repo.web_url, '_blank')
|
||||
}} className="cursor-pointer">
|
||||
<ExternalLink className="w-4 h-4 mr-2" />
|
||||
访问仓库
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem onClick={() => handleIssue(repo)} className="cursor-pointer">
|
||||
<IssueIcon className="w-4 h-4 mr-2" />
|
||||
访问问题
|
||||
|
||||
@@ -126,7 +126,10 @@ const DevTabContent = ({ linkItems, workspaceLink, stopWorkspace }: {
|
||||
|
||||
// Work tab 内容(暂留,需要根据 business_id 做事情)
|
||||
const WorkTabContent = () => {
|
||||
const store = useRepoStore(useShallow((state) => ({ selectWorkspace: state.selectWorkspace })))
|
||||
const store = useRepoStore(useShallow((state) => ({
|
||||
selectWorkspace: state.selectWorkspace,
|
||||
workspaceLink: state.workspaceLink,
|
||||
})))
|
||||
const businessId = store.selectWorkspace?.business_id;
|
||||
|
||||
const appList = [
|
||||
@@ -139,11 +142,23 @@ const WorkTabContent = () => {
|
||||
{
|
||||
title: 'OpenClaw', key: 'OpenClaw', port: 80, end: '/openclaw'
|
||||
},
|
||||
{
|
||||
key: 'vscode' as LinkItemKey,
|
||||
title: 'VS Code',
|
||||
icon: <Code2 className="w-5 h-5" />,
|
||||
},
|
||||
{
|
||||
title: 'OpenWebUI', key: 'OpenWebUI', port: 200, end: ''
|
||||
},
|
||||
]
|
||||
const links = appList.map(app => {
|
||||
if (app.icon) {
|
||||
return {
|
||||
label: app.title,
|
||||
icon: app.icon,
|
||||
url: store?.workspaceLink?.[app.key as LinkItemKey] as string | undefined
|
||||
}
|
||||
}
|
||||
const url = `https://${businessId}-${app.port}.cnb.run${app.end}`
|
||||
return {
|
||||
label: app.title,
|
||||
|
||||
@@ -11,7 +11,8 @@ export const App = () => {
|
||||
const repoStore = useRepoStore(useShallow((state) => ({
|
||||
getItem: state.getItem,
|
||||
editRepo: state.editRepo,
|
||||
refresH: state.refresh,
|
||||
refresh: state.refresh,
|
||||
loading: state.loading,
|
||||
})));
|
||||
const [activeTab, setActiveTab] = useState(params.tab || "build");
|
||||
const tabs = [
|
||||
@@ -21,7 +22,7 @@ export const App = () => {
|
||||
useEffect(() => {
|
||||
if (params.repo) {
|
||||
repoStore.getItem(params.repo);
|
||||
repoStore.refresH({ search: params.repo, showTips: false });
|
||||
repoStore.refresh({ search: params.repo, showTips: false });
|
||||
} else {
|
||||
console.log('no repo param')
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export const createCommitBlankConfig = (params: { repo?: string, event: 'api_tri
|
||||
|
||||
export const createDevConfig = (params: { repo?: string, event?: string, branch?: string }) => {
|
||||
const event = params?.event || 'api_trigger_event';
|
||||
const branch = params?.branch || 'main';
|
||||
const branch = params?.branch || '$';
|
||||
return `##### 配置开始,保留注释 #####
|
||||
.common_env: &common_env
|
||||
env:
|
||||
@@ -95,8 +95,6 @@ ${branch}:
|
||||
imports: !reference [.common_env, imports]
|
||||
env: !reference [.common_env, env]
|
||||
stages:
|
||||
- name: 环境变量
|
||||
script: printenv > ~/.env.development
|
||||
- name: 启动nginx
|
||||
script: nginx
|
||||
- name: 初始化开发机
|
||||
|
||||
Reference in New Issue
Block a user