diff --git a/apps/git/20260228-000000/index.tsx b/apps/git/20260228-000000/index.tsx index c011803..712f978 100644 --- a/apps/git/20260228-000000/index.tsx +++ b/apps/git/20260228-000000/index.tsx @@ -96,11 +96,24 @@ const RepoName = define('RepoName', { // Interfaces // --------------------------------------------------------------------------- +interface AppRepoProps { + appName: string + baseUrl: string + branch: string + exists: boolean + commits: boolean +} + interface LayoutProps { title: string children: Child } +interface RepoListPageProps { + baseUrl: string + repos: Array<{ name: string; commits: boolean; branch: string }> +} + // --------------------------------------------------------------------------- // Functions // --------------------------------------------------------------------------- @@ -400,6 +413,123 @@ async function withDeployLock(repo: string, fn: () => Promise): Promise } } +function AppRepo({ appName, baseUrl, branch, exists, commits }: AppRepoProps) { + return ( + + {exists && commits ? ( + <> + Repository + + +
+ {appName} + + git clone {baseUrl}/{appName}.git + +
+
+ {branch} + deployed +
+
+
+ + Push Changes + {[ + `git push toes ${branch}`, + '', + '# Or if remote not yet added:', + `git remote add toes ${baseUrl}/${appName}.git`, + `git push toes ${branch}`, + ].join('\n')} + + ) : exists ? ( + <> + Repository + + +
+ {appName} + + git clone {baseUrl}/{appName}.git + +
+ empty +
+
+ + Push to Deploy + {[ + `git remote add toes ${baseUrl}/${appName}.git`, + 'git push toes main', + ].join('\n')} + + ) : ( + <> + Push to Deploy + + No git repository for {appName} yet. + Push to create one and deploy. + + {[ + `git remote add toes ${baseUrl}/${appName}.git`, + 'git push toes main', + ].join('\n')} + + )} +
+ ) +} + +function RepoListPage({ baseUrl, repos }: RepoListPageProps) { + return ( + + Push to Deploy + + Push a git repository to deploy it as a toes app. + The repo must contain a package.json with a scripts.toes entry. + + + {[ + '# Add this server as a remote and push', + `git remote add toes ${baseUrl}/.git`, + 'git push toes main', + '', + '# Or push an existing repo', + `git push ${baseUrl}/.git main`, + ].join('\n')} + + {repos.length > 0 && ( + <> + Repositories + + {repos.map(({ name, commits, branch }) => ( + +
+ {name} + + git clone {baseUrl}/{name}.git + +
+
+ {branch} + {commits + ? deployed + : empty} +
+
+ ))} +
+ + )} + + {repos.length === 0 && ( + No repositories yet. Push one to get started. + )} +
+ ) +} + // --------------------------------------------------------------------------- // Module init // --------------------------------------------------------------------------- @@ -515,128 +645,18 @@ app.get('/', async c => { ? await Promise.all([hasCommits(bare), getDefaultBranch(bare)]) : [false, 'main'] - return c.html( - - {exists && commits ? ( - <> - Repository - - -
- {appName} - - git clone {baseUrl}/{appName}.git - -
-
- {branch} - deployed -
-
-
- - Push Changes - {[ - `git push toes ${branch}`, - '', - '# Or if remote not yet added:', - `git remote add toes ${baseUrl}/${appName}.git`, - `git push toes ${branch}`, - ].join('\n')} - - ) : exists ? ( - <> - Repository - - -
- {appName} - - git clone {baseUrl}/{appName}.git - -
- empty -
-
- - Push to Deploy - {[ - `git remote add toes ${baseUrl}/${appName}.git`, - 'git push toes main', - ].join('\n')} - - ) : ( - <> - Push to Deploy - - No git repository for {appName} yet. - Push to create one and deploy. - - {[ - `git remote add toes ${baseUrl}/${appName}.git`, - 'git push toes main', - ].join('\n')} - - )} -
, - ) + return c.html() } // No app selected — show all repos const repos = await listRepos() - const repoData = await Promise.all(repos.map(async name => { const bare = repoPath(name) const [commits, branch] = await Promise.all([hasCommits(bare), getDefaultBranch(bare)]) return { name, commits, branch } })) - return c.html( - - Push to Deploy - - Push a git repository to deploy it as a toes app. - The repo must contain a package.json with a scripts.toes entry. - - - {[ - '# Add this server as a remote and push', - `git remote add toes ${baseUrl}/.git`, - 'git push toes main', - '', - '# Or push an existing repo', - `git push ${baseUrl}/.git main`, - ].join('\n')} - - {repoData.length > 0 && ( - <> - Repositories - - {repoData.map(({ name, commits, branch }) => ( - -
- {name} - - git clone {baseUrl}/{name}.git - -
-
- {branch} - {commits - ? deployed - : empty} -
-
- ))} -
- - )} - - {repoData.length === 0 && ( - No repositories yet. Push one to get started. - )} -
, - ) + return c.html() }) export default app.defaults