Skip to content

Commit

Permalink
sorted out the pull of the branches
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegMoshkovich committed Oct 27, 2022
1 parent 9413b64 commit c6b06e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
30 changes: 12 additions & 18 deletions src/Components/BranchesControl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import TextField from '@mui/material/TextField'
import MenuItem from '@mui/material/MenuItem'
import Paper from '@mui/material/Paper'
import Typography from '@mui/material/Typography'
// import TextField from '@mui/material/TextField'
import {makeStyles} from '@mui/styles'
import {ColorModeContext} from '../Context/ColorMode'
import debug from '../utils/debug'
Expand All @@ -19,13 +18,13 @@ import useStore from '../store/useStore'
*/
export default function Branches() {
const classes = useStyles()
const [selected, setSelected] = useState(1)
const navigate = useNavigate()
const colorMode = useContext(ColorModeContext)
const repository = useStore((state) => state.repository)
const [branchNames, setBranchNames] = useState([])
const [versionPaths, setVersionPaths] = useState([])
const modelPath = useStore((state) => state.modelPath)
// const [version, setVersion] = useState([])
const minVersions = 2

useEffect(() => {
if (!repository) {
Expand All @@ -35,14 +34,16 @@ export default function Branches() {
const fetchBranches = async () => {
try {
const branchesData = await getBranches(repository)
const branchPaths = []
const versionPathsLocal = []
if (branchesData.data.length > 0) {
setBranchNames(branchesData.data)
}
branchesData.data.map((branch) => {
modelPath.branch = branch.name
branchPaths.push(modelPath.branch)
const versionPath = `/share/v/gh/${modelPath.org}/${modelPath.repo}/${modelPath.branch}${modelPath.filepath}`
versionPathsLocal.push(versionPath)
})
setVersionPaths(versionPathsLocal)
} catch (e) {
debug().warn('failed to fetch issues', e)
}
Expand All @@ -53,41 +54,34 @@ export default function Branches() {
}, [repository])


const handleSelect = (option) => {
console.log('option', option.target.value)
setSelected(option.target.value)
const modelPath1 = {
// 0: '/share/v/gh/Swiss-Property-AG/Seestrasse-Public/main/SEESTRASSE.ifc#c:119.61,50.37,73.68,16.18,11.25,5.74',
// 1: '/share/v/gh/Swiss-Property-AG/Seestrasse-Public/Version-1/SEESTRASSE.ifc#c:119.61,50.37,73.68,16.18,11.25,5.74',
// 2: '/share/v/gh/IFCjs/test-ifc-files/main/Schependomlaan/IFC%20Schependomlaan.ifc#c:60.45,-4.32,60.59,1.17,5.93,-3.77',
}
const handleSelect = (event) => {
const versionNumber = event.target.value
navigate({
pathname: modelPath1[option],
pathname: versionPaths[versionNumber],
})
}

return (
<Paper elevation={0}
sx={{
backgroundColor: colorMode.isDay() ? '#E8E8E8' : '#4C4C4C',
marginTop: '14px',
opacity: .8,
display: ( modelPath.repo !== undefined && branchNames.length ) < minVersions ? 'none' : 'box',
}}
>
<TextField
className={classes.dropDown}
value={selected}
onChange={(e) => handleSelect(e)}
variant='outlined'
label='Version'
label='Versions'
select
>
{branchNames.length > 0 && branchNames.map((branchName, i) => {
console.log('selected', branchNames[selected].name === branchName.name )
return (
<MenuItem
key={i}
value={i}
selected={branchNames[selected].name === branchName.name}
>
<Typography variant='p'>{branchName.name}</Typography>
</MenuItem>
Expand Down
5 changes: 1 addition & 4 deletions src/Containers/CadView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {Color, MeshLambertMaterial} from 'three'
import {IfcViewerAPI} from 'web-ifc-viewer'
import {useNavigate, useSearchParams, useLocation} from 'react-router-dom'
import {makeStyles} from '@mui/styles'
import Box from '@mui/material/Box'
import * as Privacy from '../privacy/Privacy'
import Alert from '../Components/Alert'
import debug from '../utils/debug'
Expand Down Expand Up @@ -464,9 +463,7 @@ export default function CadView({
<SearchBar
fileOpen={loadLocalFile}
/>
<Box sx={{marginTop: '14px'}}>
<BranchesControl />
</Box>
<BranchesControl />
{showNavPanel &&
<NavPanel
model={model}
Expand Down

0 comments on commit c6b06e6

Please sign in to comment.