Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: New articles #262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions sanity/schemas/article-new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { localize } from "../utils/locale";

export default {
title: "New article",
name: "newArticle",
type: "document",
fields: [
{
title: "Article title",
name: "articleTitle",
type: "string"
},
{
title: "Article Content",
name: "articleContent",
type: "array",
of: [
localize(
{
title: "Body",
name: "body",
type: "array",
of: [
{ type: "block" },
{
type: "image",
options: { hotspot: true }
},
{ type: "youtube" },
{ type: "iframe" }
]
},
(lang, Rule) => (lang.isDefault ? Rule.required() : undefined)
),
{
title: "Quotes",
name: "quotes",
type: "object",
fields: [
{
title: "Quote text",
name: "quoteText",
type: "string"
}
]
}
]
}
]
};
4 changes: 3 additions & 1 deletion sanity/schemas/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import externalLink from "./types/external-link";
import internalLink from "./types/internal-link";
import youtube from "./types/youtube";
import iframe from "./types/iframe";
import articleNew from "./article-new";

// Then we give our schema to the builder and provide the result to Sanity
export default createSchema({
Expand Down Expand Up @@ -70,6 +71,7 @@ export default createSchema({
internalLink,
externalLink,
youtube,
iframe
iframe,
articleNew
])
});
2 changes: 2 additions & 0 deletions web/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import ErrorPage from "./pages/error";
import Partner from "./pages/partner";
import Live from "./pages/live";
import NewArticle from "./pages/new-article";

const App: React.FC = () => {
const { data, error } = useSWR<
Expand Down Expand Up @@ -65,6 +66,7 @@ const App: React.FC = () => {
<FrontPage path="/" />
<Page path="/p/:slug" />
<Article path="/a/:slug" />
<NewArticle path="/new-articles" />
<ArticleOverview path="/articles" />
<EventOverview path="/events" />
<Live path="/live" />
Expand Down
30 changes: 30 additions & 0 deletions web/src/pages/new-article.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import { RouteComponentProps } from "@reach/router";
import useSWR from "swr";
import { SanityNewArticle } from "../sanity/models";
import Loading from "../components/loading";
import NotFound from "./not-found";
import Error from "./error";

type Props = { slug?: string } & RouteComponentProps;

const NewArticle: React.FC<Props> = () => {
// const { slug } = props;

const { data: article, error } = useSWR<SanityNewArticle>(
`*[_type == "newArticle"][0]{...}`
);
console.log("new article ", article);

if (error) return <Error error={JSON.stringify(error)} />;
if (article === undefined) return <Loading />;
if (article === null) return <NotFound />;

return (
<div>
<h1>New Article</h1>
</div>
);
};

export default NewArticle;
25 changes: 25 additions & 0 deletions web/src/sanity/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,31 @@ export type SanityArticle = SanityDocument<
}
>;

export type SanityNewArticle = SanityDocument<
"newArticle",
{
// slug: { current: string };
title: Locale<string>;
// publishedAt: string;
articleContent: Locale<
SanityObjectArray<
| SanityBlock
| SanityObject<
"quotes",
{
title: string;
}
>
>
>;

// image: SanityImage;
// summary: Locale<string>;
// body: Locale<SanityObjectArray<SanityBlock>>;
// credits: Locale<string>;
}
>;

export type SanityArticleList = Array<SanityArticle>;

export type SanityArchive = SanityDocument<
Expand Down