-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* get all information needed for requests without a body * wip * copy request information in hash * get mvp working * style and handle old browsers * clean * abstract out reused code * handle badmagic mounted on routes other than root * make link itself the copy button * only encode necessary data * fix: eslint config for lsp * fix: load full route definition from workspaces * fix: everything loading correctly and handle undefined base url * fix: move workspace defaults to top level and handle broken link
- Loading branch information
Showing
12 changed files
with
249 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { cloneDeep, first } from "lodash-es"; | ||
import { useMemo } from "react"; | ||
import { Helpers } from ".."; | ||
import { useGlobalContext } from "../context/GlobalContext"; | ||
import { HistoricResponse, Route } from "../types"; | ||
|
||
export function useActiveResponse(activeRoute: Route): HistoricResponse { | ||
const { historicResponses, partialRequestResponses } = useGlobalContext(); | ||
|
||
const filteredHistory = useMemo( | ||
() => Helpers.filterHistory(historicResponses, activeRoute), | ||
[historicResponses, activeRoute] | ||
); | ||
|
||
return useMemo(() => { | ||
// Prefers in-memory state changes that already began since the session started | ||
// Falls back to loading the last HistoricResponse from history if set | ||
// Falls back to a new partial HistoricRepsonse if the first two conditions aren't met. | ||
if (partialRequestResponses[activeRoute.path]) { | ||
return partialRequestResponses[activeRoute.path]; | ||
} else if (filteredHistory.length) { | ||
return cloneDeep(first(filteredHistory)) as HistoricResponse; | ||
} | ||
|
||
return { | ||
metadata: {}, | ||
response: null, | ||
error: null, | ||
urlParams: {}, | ||
qsParams: Helpers.reduceDefaultParamValues(activeRoute?.qsParams), | ||
body: Helpers.reduceDefaultParamValues(activeRoute?.body), | ||
route: activeRoute, | ||
}; | ||
}, [activeRoute, filteredHistory, partialRequestResponses]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.