-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create interfaces, get and render initial data from slices
- Loading branch information
Grazia Palombella
committed
Dec 21, 2022
1 parent
7af75f3
commit 64ee97b
Showing
10 changed files
with
1,333 additions
and
1,167 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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,16 @@ | ||
import React from 'react' | ||
|
||
interface CommentComponentProps { | ||
readonly children: React.ReactNode | ||
} | ||
|
||
|
||
const CommentComponent = (props: CommentComponentProps) => { | ||
return ( | ||
<> | ||
{props.children} | ||
</> | ||
) | ||
} | ||
|
||
export default CommentComponent |
This file contains 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,14 @@ | ||
import React from 'react' | ||
import { User } from '../redux/slices/commentsSlice' | ||
|
||
interface UserProps { | ||
readonly user: User | ||
} | ||
|
||
const User = (props: UserProps) => { | ||
return ( | ||
<div>{props.user.username}</div> | ||
) | ||
} | ||
|
||
export default User |
This file contains 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,7 @@ | ||
import { useDispatch, useSelector } from "react-redux"; | ||
|
||
import type { TypedUseSelectorHook } from "react-redux"; | ||
import type { RootState, AppDispatch } from "../store"; | ||
|
||
export const useAppDispatch: () => AppDispatch = useDispatch | ||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector |
This file contains 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,55 @@ | ||
|
||
import { createSlice } from "@reduxjs/toolkit"; | ||
|
||
import initialCommentsRaw from '../../data.json' | ||
|
||
const initialComments: Data = initialCommentsRaw | ||
|
||
|
||
interface Image { | ||
png: string | ||
webp: string | ||
} | ||
|
||
export interface User { | ||
image: Image | ||
username: string | ||
} | ||
|
||
type Replies = Omit<Comment, 'replies'> & { replyingTo: string } | ||
|
||
export interface Data { | ||
currentUser: User | ||
comments: Comment[] | ||
} | ||
|
||
export interface Comment { | ||
id: number | ||
content: string | ||
createdAt: string | ||
score: number | ||
user: User | ||
replies: Replies[] | ||
} | ||
|
||
interface CommentState { | ||
loading: boolean | ||
error: null | string | ||
data: null | Data | ||
} | ||
|
||
const initialState = { | ||
loading: false, | ||
error: null, | ||
data: initialComments | ||
} as CommentState | ||
|
||
const commentsSlice = createSlice({ | ||
name: 'comments', | ||
initialState: initialState, | ||
reducers: { | ||
|
||
}, | ||
}) | ||
|
||
export default commentsSlice.reducer |
This file contains 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 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