-
-
Notifications
You must be signed in to change notification settings - Fork 156
Admin Tab for MAPLE News Items #2055 #2061
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
Open
ACoullard
wants to merge
5
commits into
codeforboston:main
Choose a base branch
from
ACoullard:in-the-news-admin-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| export * from "./bills" | ||
| export * from "./createTableHook" | ||
| export * from "./members" | ||
| export * from "./news" | ||
| export * from "./profile" | ||
| export * from "./testimony" | ||
| export * from "./useUpcomingBills" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { collection, getDocs, orderBy, Timestamp } from "firebase/firestore" | ||
| import { useAsync } from "react-async-hook" | ||
| import { firestore } from "../firebase" | ||
|
|
||
| export type NewsType = "article" | "award" | "book" | ||
|
|
||
| export type NewsItem = { | ||
| id: string | ||
| url: string | ||
| title: string | ||
| author: string | ||
| type: NewsType | ||
| description?: string | ||
| publishDate: string | ||
| createdAt: Timestamp | ||
| } | ||
|
|
||
| export async function listNews(): Promise<NewsItem[]> { | ||
| const newsRef = collection(firestore, "news") | ||
| const result = await getDocs(newsRef) | ||
| return result.docs.map(d => ({ id: d.id, ...d.data() } as NewsItem)) | ||
| } | ||
|
|
||
| export function useNews() { | ||
| return useAsync(listNews, []) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import React, { useEffect } from "react" | ||
| import { collection, getFirestore, onSnapshot } from "firebase/firestore" | ||
| import { | ||
| Create, | ||
| Datagrid, | ||
| DateField, | ||
| DateInput, | ||
| Edit, | ||
| EditButton, | ||
| FunctionField, | ||
| List, | ||
| SelectInput, | ||
| SimpleForm, | ||
| TextField, | ||
| TextInput, | ||
| useRefresh | ||
| } from "react-admin" | ||
|
|
||
| const typeChoices = [ | ||
| { id: "article", name: "Article" }, | ||
| { id: "award", name: "Award" }, | ||
| { id: "book", name: "Book" } | ||
| ] | ||
|
|
||
| export function ListNews() { | ||
| const firestore = getFirestore() | ||
| const refresh = useRefresh() | ||
|
|
||
| useEffect(() => { | ||
| const newsRef = collection(firestore, "news") | ||
| const unsubscribe = onSnapshot( | ||
| newsRef, | ||
| () => refresh(), | ||
| (e: Error) => console.log(e) | ||
| ) | ||
|
|
||
| return () => unsubscribe() | ||
| }, [firestore, refresh]) | ||
|
|
||
| return ( | ||
| <List> | ||
| <Datagrid rowClick="edit" bulkActionButtons={false}> | ||
| <TextField source="id" label="News ID" /> | ||
| <TextField source="title" label="Title" /> | ||
| <TextField source="author" label="Author" /> | ||
| <TextField source="type" label="Type" /> | ||
| <DateField source="publishDate" label="Publish Date" /> | ||
| <DateField source="createdAt" showTime /> | ||
| <EditButton label="Edit" /> | ||
| </Datagrid> | ||
| </List> | ||
| ) | ||
| } | ||
|
|
||
| export function EditNews() { | ||
| return ( | ||
| <Edit> | ||
| <SimpleForm> | ||
| <TextInput source="url" fullWidth /> | ||
| <SelectInput source="type" choices={typeChoices} /> | ||
| <TextInput source="author" /> | ||
| <TextInput source="title" fullWidth /> | ||
| <TextInput source="description" multiline fullWidth /> | ||
| <DateInput source="publishDate" /> | ||
| </SimpleForm> | ||
| </Edit> | ||
| ) | ||
| } | ||
|
|
||
| export function CreateNews() { | ||
| return ( | ||
| <Create redirect="list" transform={(data: Record<string, unknown>) => ({ ...data, createdAt: new Date() })}> | ||
| <SimpleForm> | ||
| <TextInput source="url" fullWidth /> | ||
| <SelectInput source="type" choices={typeChoices} /> | ||
| <TextInput source="author" /> | ||
| <TextInput source="title" fullWidth /> | ||
| <TextInput source="description" multiline fullWidth /> | ||
| <DateInput source="publishDate" /> | ||
| </SimpleForm> | ||
| </Create> | ||
| ) | ||
| } | ||
|
|
||
| export default { ListNews, EditNews, CreateNews } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since new "news
items"have no inherent "id" that can be used for this, I have altered the method here to allow firestore to auto generate one if none is provided