mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
Make Camera app use router (#69)
* Make Camera app use router * Remove unused hooks * Fucking communicate messages with camera with router * Improved sharing in messages flow * Fix clipboard * Removeunused imports * improve routing helpers * Fix bug :D * Fix stupid thing * Add docs to useQueryParams hook
This commit is contained in:
1 parent
447c51a07e
commit
40f9555b39
34 files changed
+481
-294
No files matched your search
@@ -0,0 +1,16 @@
|
||||
import qs, { ParsedQs } from 'qs';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
|
||||
/**
|
||||
* Parses all available query params in current location and returns as an object
|
||||
*
|
||||
* @return {T} Querystring object
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* const { id, title } = useQueryParams<{ id: string, title: string }>();
|
||||
*/
|
||||
export function useQueryParams<T = Record<string, string>>() {
|
||||
return qs.parse(useLocation().search, { ignoreQueryPrefix: true }) as T &
|
||||
Partial<ParsedQs>;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import qs from 'qs';
|
||||
import url from 'parse-url';
|
||||
|
||||
interface IRouterLocation {
|
||||
pathname: string;
|
||||
search: string;
|
||||
}
|
||||
|
||||
export const addQueryToLocation = (
|
||||
{ pathname = '', search = '' }: Record<string, unknown> & IRouterLocation,
|
||||
key = '',
|
||||
value = ''
|
||||
) => {
|
||||
const { query } = url(pathname + search);
|
||||
return `${pathname}?${qs.stringify({
|
||||
...query,
|
||||
[key]: value,
|
||||
})}`;
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
import qs from 'qs';
|
||||
import url from 'parse-url';
|
||||
|
||||
interface IRouterLocation {
|
||||
pathname: string;
|
||||
search: any;
|
||||
}
|
||||
|
||||
export const deleteQueryFromLocation = (
|
||||
location: Record<string, unknown> & IRouterLocation,
|
||||
key = ''
|
||||
) => {
|
||||
const { query } = url(location.pathname + location.search);
|
||||
return `${location.pathname}/?${qs.stringify({
|
||||
...query,
|
||||
[key]: undefined,
|
||||
})}`;
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import parseUrl from 'parse-url';
|
||||
|
||||
export const getLocationFromUrl = (url: String) => {
|
||||
const { pathname, search } = parseUrl(url);
|
||||
const searchStr = '?' + (search || '');
|
||||
return { pathname, search: searchStr };
|
||||
};
|
||||
Reference in new issue
Block a user