Skip to content

Commit

Permalink
Routing: use string id
Browse files Browse the repository at this point in the history
  • Loading branch information
wildmolasses committed Nov 10, 2023
1 parent 8e32265 commit 1843714
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 31 deletions.
18 changes: 9 additions & 9 deletions components/DaoMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { Menu, Transition } from '@headlessui/react';
import { ChevronDownIcon } from '@heroicons/react/20/solid';
import { useConfig } from '@/hooks/useConfig';

type Option<T> = {
value: T;
type Option = {
daoId: string;
label: string;
logo: string;
};

type Props<T> = {
options: Option<T>[];
type Props = {
options: Option[];
};

const DaoMenu = <T,>(props: Props<T>) => {
const DaoMenu = (props: Props) => {
const config = useConfig();
return (
<Menu as="div" className="relative inline-block text-left">
Expand Down Expand Up @@ -45,15 +45,15 @@ const DaoMenu = <T,>(props: Props<T>) => {
>
<Menu.Items className="absolute right-0 z-10 mt-2 w-44 origin-top-right rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
<div className="py-1">
{props.options.map((option, key) => (
<Menu.Item key={key}>
{props.options.map((option, index) => (
<Menu.Item key={index}>
{({ active }) => {
return (
<Link
href={`/${option.value}/bridge`}
href={`/${option.daoId}/bridge`}
className={clsx(
active ? ' flex bg-gray-100 text-gray-900' : 'text-gray-700',
'flex block px-4 py-2 text-sm'
'flex px-4 py-2 text-sm'
)}
>
<Image
Expand Down
12 changes: 5 additions & 7 deletions components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import { useConfig } from '@/hooks/useConfig';
import { useDebugPanel } from '@/contexts/DebugPanel';
import DaoMenu from '@/components/DaoMenu';
import { DEFAULT_DAO_ID } from '@/util/constants';
import { config } from '@/config';

const options = [
{ label: 'Example', value: 1, logo: '/pooltogetherLogo.svg' },
{ label: 'ExampleComp', value: 2, logo: '/gitcoinLogo.svg' },
{ label: 'PoolTogether', value: 3, logo: '/poolTogether.svg' },
{ label: 'Gitcoin', value: 4, logo: '/gitcoinLogo.svg' },
];
const options = Object.entries(config).map(([daoId, configEntry]) => {
return { daoId, label: configEntry.name, logo: configEntry.daoLogo };
});

export const Header = () => {
const { showDebug } = useConfig();
Expand Down Expand Up @@ -49,7 +47,7 @@ const NavButtons = () => {
{ name: 'Stats', href: `/${id}/stats` },
];

const current = tabs.find((tab) => tab.href === pathname);
const current = tabs.find((tab) => pathname.includes(tab.href.split('/').at(-1) as string));

return (
<div>
Expand Down
8 changes: 4 additions & 4 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { goerli, optimismGoerli } from 'wagmi/chains';
export const chains = [goerli, optimismGoerli];

export enum DaoId {
Example = 1,
ExampleComp = 2,
PoolTogether = 3,
Gitcoin = 4,
Example = 'example',
ExampleComp = 'example-comp',
PoolTogether = 'pool-together',
Gitcoin = 'gitcoin',
}

export const config = {
Expand Down
10 changes: 2 additions & 8 deletions hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ export const useConfig = () => {
if (Array.isArray(query.id)) {
throw new Error('Too many ids have been specified');
}
if (Number(query?.id) === DaoId.Example) {
if (!query.id || !(query.id in config)) {
return config[DaoId.Example];
} else if (Number(query?.id) === DaoId.ExampleComp) {
return config[DaoId.ExampleComp];
} else if (Number(query?.id) === DaoId.PoolTogether) {
return config[DaoId.PoolTogether];
} else if (Number(query?.id) === DaoId.Gitcoin) {
return config[DaoId.Gitcoin];
}
return config[DaoId.Example];
return config[query.id as DaoId];
};
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[[redirects]]
from = "/"
to = "/1/bridge"
to = "/example/bridge"
status = 302
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const nextConfig = {
return [
{
source: '/',
destination: '/1/bridge',
destination: '/example/bridge',
permanent: false,
},
];
Expand Down
2 changes: 1 addition & 1 deletion util/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
export const DEFAULT_DAO_ID = 1;
export const DEFAULT_DAO_ID = 'example';

0 comments on commit 1843714

Please sign in to comment.