[refactor,#59][s]: move packages/portal => examples/catalog as per plan in #59.
What is currently packages/portal is example of a running portal and should move to examples (it will get replaced by an actual portal lib soon).
This commit is contained in:
55
examples/catalog/pages/[org]/[dataset]/index.tsx
Normal file
55
examples/catalog/pages/[org]/[dataset]/index.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
import { GetServerSideProps } from 'next';
|
||||
import { useQuery } from '@apollo/react-hooks';
|
||||
import Head from 'next/head';
|
||||
import { initializeApollo } from '../../../lib/apolloClient';
|
||||
import Nav from '../../../components/home/Nav';
|
||||
import About from '../../../components/dataset/About';
|
||||
import Org from '../../../components/dataset/Org';
|
||||
import Resources from '../../../components/dataset/Resources';
|
||||
import { GET_DATASET_QUERY } from '../../../graphql/queries';
|
||||
|
||||
const Dataset: React.FC<{ variables: any }> = ({ variables }) => {
|
||||
const { data, loading } = useQuery(GET_DATASET_QUERY, { variables });
|
||||
|
||||
if (loading) return <div>Loading</div>;
|
||||
const { result } = data.dataset;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Portal | {result.title || result.name}</title>
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
<Nav />
|
||||
<main className="p-6">
|
||||
<h1 className="text-3xl font-semibold text-primary mb-2">
|
||||
{result.title || result.name}
|
||||
</h1>
|
||||
<Org variables={variables} />
|
||||
<About variables={variables} />
|
||||
<Resources variables={variables} />
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
const apolloClient = initializeApollo();
|
||||
const variables = {
|
||||
id: context.query.dataset,
|
||||
};
|
||||
|
||||
await apolloClient.query({
|
||||
query: GET_DATASET_QUERY,
|
||||
variables,
|
||||
});
|
||||
|
||||
return {
|
||||
props: {
|
||||
initialApolloState: apolloClient.cache.extract(),
|
||||
variables,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default Dataset;
|
||||
@@ -0,0 +1,57 @@
|
||||
import { GetServerSideProps } from 'next';
|
||||
import { useQuery } from '@apollo/react-hooks';
|
||||
import Head from 'next/head';
|
||||
import { initializeApollo } from '../../../../../lib/apolloClient';
|
||||
import Nav from '../../../../../components/home/Nav';
|
||||
import About from '../../../../../components/resource/About';
|
||||
import DataExplorer from '../../../../../components/resource/DataExplorer';
|
||||
import { GET_RESOURCES_QUERY } from '../../../../../graphql/queries';
|
||||
|
||||
const Resource: React.FC<{ variables: any }> = ({ variables }) => {
|
||||
const { data, loading } = useQuery(GET_RESOURCES_QUERY, { variables });
|
||||
|
||||
if (loading) return <div>Loading</div>;
|
||||
const result = data.dataset.result;
|
||||
// Find right resource
|
||||
const resource = result.resources.find(
|
||||
(item) => item.name === variables.resource
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Portal | {resource.title || resource.name}</title>
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
<Nav />
|
||||
<main className="p-6">
|
||||
<h1 className="text-3xl font-semibold text-primary mb-2">
|
||||
{resource.title || resource.name}
|
||||
</h1>
|
||||
<About variables={variables} />
|
||||
<DataExplorer variables={variables} />
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
const apolloClient = initializeApollo();
|
||||
const variables = {
|
||||
id: context.query.dataset,
|
||||
resource: context.query.resource,
|
||||
};
|
||||
|
||||
await apolloClient.query({
|
||||
query: GET_RESOURCES_QUERY,
|
||||
variables,
|
||||
});
|
||||
|
||||
return {
|
||||
props: {
|
||||
initialApolloState: apolloClient.cache.extract(),
|
||||
variables,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default Resource;
|
||||
Reference in New Issue
Block a user