Skip to content

Commit

Permalink
buck2: explain: add comments
Browse files Browse the repository at this point in the history
Summary: Some of these aren't very straightforward, so writing it down for my future self

Reviewed By: samkevich

Differential Revision: D57091801

fbshipit-source-id: 3aa746e547f08cd1921a4e0733eafbe3d03faa3a
  • Loading branch information
iguridi authored and facebook-github-bot committed May 9, 2024
1 parent 9c1bad6 commit f5f3f59
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/buck2_explain/js/src/App.tsx
Expand Up @@ -32,6 +32,10 @@ export const CurrentTargetContext = React.createContext<{
setTarget: (target: ConfiguredTargetNode | null) => void
}>({target: null, setTarget: () => {}})

/**
* Sets the current target based on the 'target' URL parameter.
* If the parameter is not present, it defaults to the root target.
*/
function fromUrl(
data: STATE_TYPE,
currentTarget: ConfiguredTargetNode | null,
Expand All @@ -49,6 +53,9 @@ function fromUrl(
}
}

/**
* Acts as a normal webpage banner, where clicking on it sends the user back to the root page of the website
*/
function RootSpan(props: {setCurrentTarget: (target: ConfiguredTargetNode | null) => void}) {
const {rootTarget} = useContext(DataContext)

Expand All @@ -68,6 +75,9 @@ function App() {

const [currentTarget, setCurrentTarget] = useState<ConfiguredTargetNode | null>(null)

/**
* Wrapper around setCurrentTarget to set url query params
*/
const setCurrentTargetAndUrl = (target: ConfiguredTargetNode | null) => {
const label = target?.configuredTargetLabel()
if (label == null) return
Expand All @@ -85,6 +95,9 @@ function App() {
setCurrentTarget(target)
}

/**
* Updates target every time the user goes back in history
*/
useEffect(() => {
// This is triggered every time the user goes back in history
const f = () => {
Expand All @@ -96,6 +109,9 @@ function App() {
}
}, [data, currentTarget])

/**
* Loads initial information on page load
*/
useEffect(() => {
const fetchData = async () => {
try {
Expand Down

0 comments on commit f5f3f59

Please sign in to comment.