feat: hydrate QuickCommand from API

This commit is contained in:
Ravinou 2023-09-05 22:03:39 +02:00
parent 85f30d7ce7
commit d4c62e8572
No known key found for this signature in database
GPG key ID: EEEE670C40F6A4D7
3 changed files with 26 additions and 7 deletions

View file

@ -6,20 +6,21 @@ import { IconSettingsAutomation, IconCopy } from '@tabler/icons-react';
export default function QuickCommands(props) {
////Vars
const wizardEnv = props.wizardEnv;
//Needed to generate command for borg over LAN instead of WAN if env vars are set and option enabled.
let HOSTNAME;
let SSH_SERVER_PORT;
let UNIX_USER = process.env.NEXT_PUBLIC_UNIX_USER;
let UNIX_USER;
if (
props.lanCommand &&
process.env.NEXT_PUBLIC_HOSTNAME_LAN &&
process.env.NEXT_PUBLIC_SSH_SERVER_PORT_LAN
wizardEnv.HOSTNAME_LAN &&
wizardEnv.SSH_SERVER_PORT_LAN
) {
HOSTNAME = process.env.NEXT_PUBLIC_HOSTNAME_LAN;
SSH_SERVER_PORT = process.env.NEXT_PUBLIC_SSH_SERVER_PORT_LAN;
HOSTNAME = wizardEnv.HOSTNAME_LAN;
SSH_SERVER_PORT = wizardEnv.SSH_SERVER_PORT_LAN;
} else {
HOSTNAME = process.env.NEXT_PUBLIC_HOSTNAME;
SSH_SERVER_PORT = process.env.NEXT_PUBLIC_SSH_SERVER_PORT;
HOSTNAME = wizardEnv.HOSTNAME;
SSH_SERVER_PORT = wizardEnv.SSH_SERVER_PORT;
}
//State

View file

@ -80,6 +80,7 @@ export default function Repo(props) {
<QuickCommands
repositoryName={props.repositoryName}
lanCommand={props.lanCommand}
wizardEnv={props.wizardEnv}
/>
</div>

View file

@ -43,11 +43,27 @@ export default function RepoList() {
if (router.pathname.startsWith('/manage-repo/edit')) {
setDisplayRepoEdit(!displayRepoEdit);
}
//Fetch wizardEnv to hydrate Repo components
const fetchWizardEnv = async () => {
try {
const response = await fetch('/api/account/getWizardEnv', {
method: 'GET',
headers: {
'Content-type': 'application/json',
},
});
setWizardEnv((await response.json()).wizardEnv);
} catch (error) {
console.log('Fetching datas error');
}
};
fetchWizardEnv();
}, []);
////States
const [displayRepoAdd, setDisplayRepoAdd] = useState(false);
const [displayRepoEdit, setDisplayRepoEdit] = useState(false);
const [wizardEnv, setWizardEnv] = useState({});
////Functions
@ -107,6 +123,7 @@ export default function RepoList() {
comment={repo.comment}
lanCommand={repo.lanCommand}
repoManageEditHandler={() => repoManageEditHandler(repo.id)}
wizardEnv={wizardEnv}
></Repo>
</>
);