Skip to content

Commit

Permalink
Better spinners and a couple of other fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
snoopdave committed Sep 1, 2024
1 parent 87bc3ee commit 4225f31
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ server/deploy/local/create-secrets.sh
server/jest.config.js
/client/src/gql/
deploy/blogql/charts
create-secrets.sh
**/create-secrets.sh
**/googlecid.ts
11 changes: 9 additions & 2 deletions client/src/blogs/BlogsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {useQuery} from '@apollo/client/react/hooks/useQuery';
import {BLOGS_QUERY} from '../graphql/queries';
import React, {useState} from 'react';
import {Heading} from "../common/Heading";
import {Button, Table} from "antd";
import {Button, Spin, Table} from "antd";
import {Link} from "react-router-dom";
import {BlogEdge} from "../gql/graphql";

Expand All @@ -30,7 +30,14 @@ export function BlogsList() {
}
);

if (loading) { return (<p>Loading...</p>); }
if (loading) {
return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}>
<Spin size="large" tip="Loading blogs..." />
</div>
);
}

if (error) { return (<p>error!</p>); }
if (!data) { return (<p>no data!</p>); }

Expand Down
3 changes: 2 additions & 1 deletion client/src/common/DateTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ type TimeUnit = 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';

// for use on Entries page, e.g. "4 days ago"
export function RelativeDateTime(props: DateTimeProps) {
const updated = props.when.getTime();
const date = new Date(props.when); // Convert to Date object
const updated = date.getTime();
const span = Date.now() - updated;

const rtf = useMemo(() => new Intl.RelativeTimeFormat('en-US', { style: 'long', numeric: 'auto' }), []);
Expand Down
11 changes: 9 additions & 2 deletions client/src/entries/Drafts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {DRAFTS_QUERY} from '../graphql/queries';
import {Link, useParams} from 'react-router-dom';
import {RequireAuth} from '../common/Authentication';
import {useNavigate} from 'react-router';
import {Button, Table} from "antd";
import {Button, Spin, Table} from "antd";
import {Heading} from "../common/Heading";
import {EntryEdge} from "../gql/graphql";
import {SimpleDateTime} from "../common/DateTime";
Expand All @@ -33,7 +33,14 @@ function Drafts() {
},
});

if (loading) { return (<p>Loading...</p>); }
if (loading) {
return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}>
<Spin size="large" tip="Loading blogs..." />
</div>
);
}

if (error) { return (<p>error!</p>); }
if (!data) { return (<p>no data!</p>); }

Expand Down
11 changes: 9 additions & 2 deletions client/src/entries/Entries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {useQuery} from '@apollo/client/react/hooks/useQuery';
import {ENTRIES_QUERY} from '../graphql/queries';
import {Heading} from "../common/Heading";
import {EntryEdge} from "../gql/graphql";
import {Avatar, Button, List, Space, Tooltip} from "antd";
import {Avatar, Button, List, Space, Spin, Tooltip} from "antd";
import {stripHtml} from "string-strip-html";
import {RelativeDateTime, SimpleDateTime} from "../common/DateTime";
import {ClockCircleOutlined, EditOutlined, LinkOutlined} from "@ant-design/icons";
Expand All @@ -33,7 +33,14 @@ function Entries() {
},
});

if (loading) { return (<p>Loading...</p>); }
if (loading) {
return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}>
<Spin size="large" tip="Loading blogs..." />
</div>
);
}

if (error) { return (<p>error!</p>); }
if (!data) { return (<p>no data!</p>); }

Expand Down
23 changes: 23 additions & 0 deletions server/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
# Licensed under Apache Software License v2.
#

# public user can only do these things:
# get a list of blogs in the system
# view the public (published) entries of any blog
# cannot create a blog
# cannot view draft entries of any blog
# cannot create blog entries
# cannot update blogs
# cannot create API keys

# a logged in user can do these things:
# create one blog
# create an API key
# update blog settings
# within that blog, create, view, update and delete blog entries
# within that blog, edit settings and get an API key

scalar DateTime

schema {
Expand All @@ -16,6 +32,7 @@ interface Node {

type Blog implements Node {
created: DateTime!
# only owner of blog can access drafts of blog
drafts(first: Int, last: Int, before: String, after: String): EntryConnection
entries(first: Int, last: Int, before: String, after: String): EntryConnection
entry(id: ID!): Entry
Expand All @@ -41,6 +58,7 @@ input EntryCreateInput {
title: String
}

# only owner of blog can mutate that blog
type BlogMutation {
createEntry(entry: EntryCreateInput): Entry
delete: Node
Expand Down Expand Up @@ -79,6 +97,7 @@ input EntryUpdateInput {
title: String
}

# only user who ones blog can perform these mutations
type EntryMutation {
delete: Node
publish: Entry
Expand All @@ -98,6 +117,7 @@ type EntryConnection {
pageInfo: PageInfo!
}

# Only authenticated users can perform these mutations
type Mutation {
issueApiKey: String
blog(handle: String!): BlogMutation
Expand All @@ -118,10 +138,13 @@ type Query {
blog(handle: String!): Blog
blogForUser(userId: ID!): Blog
blogs(first: Int, last: Int, before: String, after: String): BlogConnection

# only logged in user with userId can access this
apiKeyForUser(userId: ID!): String
}

"Represents a user of BlogQL."
# only logged in user with userId can access this
type User implements Node {
"Date user was created."
created: DateTime!
Expand Down
1 change: 1 addition & 0 deletions server/src/entries/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class Entry extends Model implements Node {
blogId: {
type: DataTypes.STRING,
allowNull: false,
field: 'blog_id'
},
title: {
type: DataTypes.STRING,
Expand Down

0 comments on commit 4225f31

Please sign in to comment.