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

Movie app practice nini #2

Open
wants to merge 35 commits into
base: movie-app
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9f6e32c
add a form but it doesn't work
IAmNini Mar 21, 2022
e4d41d4
fix localsite env
IAmNini Mar 22, 2022
e3bded9
fix movie form
IAmNini Mar 22, 2022
e09739b
add rich text editor but it's one step behind
IAmNini Mar 22, 2022
45e7267
cards and pagination
IAmNini Mar 23, 2022
fe8fa92
images + side view for movie
IAmNini Mar 23, 2022
79b1a0c
getting the right posters
IAmNini Mar 23, 2022
5819692
add mantine dependencies
IAmNini Mar 24, 2022
e7be8ff
update search results page for mobile
IAmNini Mar 24, 2022
bd6466d
change heights + title link to home
IAmNini Mar 24, 2022
92e8a16
add cards + bring back text area
IAmNini Mar 25, 2022
e7eda2a
make ReviewCard and replace old cards
IAmNini Mar 28, 2022
273266b
add rich text field
IAmNini Mar 29, 2022
583062b
move the cards to separate component + do tv page
IAmNini Mar 29, 2022
d098e5f
add TvFilmCard
IAmNini Mar 29, 2022
8b9bc38
use shorthand styles
armincerf Mar 29, 2022
3eb059a
show popular results when search term empty
armincerf Mar 29, 2022
3ee1b95
use tmdb id instead of imdb id
armincerf Mar 29, 2022
351cb05
add column scroll and images at card width
IAmNini Mar 30, 2022
4e340d5
new header with logo
IAmNini Mar 31, 2022
4e07e12
add badges
IAmNini Mar 31, 2022
f66a6e8
new icon + fixed header
IAmNini Apr 1, 2022
8b19a41
new number input mainly
IAmNini Apr 1, 2022
7bf0150
refactor id to be unique
IAmNini Apr 4, 2022
c46d7de
make style changes
IAmNini Apr 4, 2022
43999b3
change details for deployment
IAmNini Apr 4, 2022
18227e2
make some tweaks so it can be deployed
armincerf Apr 4, 2022
cdcfeea
clean code + add score validation in tv
IAmNini Apr 5, 2022
1368371
add devmode to tv/movie pages
IAmNini Apr 5, 2022
a913594
add partial edit logic
IAmNini Apr 6, 2022
b9694bc
add confirm window on delete
IAmNini Apr 7, 2022
b32cc9b
add edit but what happened to movie reviews
IAmNini Apr 8, 2022
d76a1f9
changes for new deployment
IAmNini Apr 14, 2022
3165500
fixes
IAmNini May 10, 2022
5972afc
add text to copy
IAmNini May 11, 2022
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
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SKIP_PREFLIGHT_CHECK=true
SITE_BASE_URI=http://localhost:5509
GRAPHQL_PATH=/pairing/graphql
2 changes: 1 addition & 1 deletion apps/film-and-tv-ratings/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"compiler": "babel",
"outputPath": "dist/apps/film-and-tv-ratings",
"index": "apps/film-and-tv-ratings/src/index.html",
"baseHref": "/",
"baseHref": "/_apps/film-and-tv-reviews/",
"main": "apps/film-and-tv-ratings/src/main.tsx",
"tsConfig": "apps/film-and-tv-ratings/tsconfig.app.json",
"assets": [
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 0 additions & 12 deletions apps/film-and-tv-ratings/src/common.ts

This file was deleted.

33 changes: 33 additions & 0 deletions apps/film-and-tv-ratings/src/common.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Card, Image, ImageProps, Text, Paper, Button } from '@mantine/core';
import RichTextEditor from '@mantine/rte';
import axios from 'axios';

export const api_key = '99fdc21a0b0ef55c0cbc002c0ae96fd6';

export function PosterImage({
posterPath,
imageProps,
}: {
posterPath?: string | null;
imageProps?: ImageProps;
}) {
return (
<Image
height={180}
{...imageProps}
src={`https://image.tmdb.org/t/p/original/${posterPath}`}
alt="Movie poster"
/>
);
}

export const client = axios.create({
baseURL: 'https://api.themoviedb.org',
timeout: 1000,
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
});

export const devMode = window.location.hostname === 'localhost';
129 changes: 129 additions & 0 deletions apps/film-and-tv-ratings/src/components/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import {
TvFilmReview,
TvFilmReviewInput,
UpsertReviewMutationVariables,
} from '@juxt-home/site';
import { Card, Button, Text, Title, Group, Badge } from '@mantine/core';
import { RichTextEditor } from '@mantine/rte';
import { Id } from 'react-toastify';
import { PosterImage } from '../common';

export function TvFilmCard({
title,
posterPath,
overview,
badge1,
badge2,
badge3,
}: {
title: string | null;
posterPath: string | null;
overview: string | null;
badge1?: string | number | null;
badge2?: string | number | null;
badge3?: string | number | null;
}) {
return (
<Card
shadow="lg"
p="xl"
my="md"
sx={(theme) => ({
border: '0.5px solid #e7e8e7',
})}>
<Title order={2}>{title}</Title>

<Card.Section
sx={(theme) => ({
margin: '10px 0 20px 0',
})}>
<PosterImage posterPath={posterPath} imageProps={{ height: 650 }} />
</Card.Section>

<Text size="sm">{overview}</Text>

<Group
style={{
marginTop: 15,
borderTop: '0.5px solid lightgray',
paddingTop: 20,
}}>
<Badge color="orange" variant="light">
{badge1}
</Badge>
<Badge color="orange" variant="light">
{badge2}
</Badge>
<Badge color="orange" variant="light">
{badge3}
</Badge>
</Group>
</Card>
);
}

export function ReviewCard({
review,
devMode,
username,
handleDeleteFunction,
handleEditFunction,
}: {
review: TvFilmReview;
devMode?: boolean;
username?: string | null;
handleDeleteFunction?: (id: string) => Promise<void>;
handleEditFunction?: ({
reviewHTML,
score,
}: Partial<TvFilmReviewInput>) => Promise<void>;
}) {
const score = review?.score;
const id = review?.id;
return (
<Card
shadow="lg"
p="xl"
sx={(theme) => ({
border: '0.5px solid #e7e8e7',
})}>
<Text weight={700} my="md">
Review by {review?._siteSubject || 'admin'}:
</Text>
{review?.reviewHTML && (
<RichTextEditor
readOnly
my="md"
value={review?.reviewHTML}
id="review"
onChange={() => null}
/>
)}
<Text>Score: {score}</Text>
{/* <Text>Recommended: {review.recommended ? 'true' : 'false'}</Text> */}

{(devMode || review?._siteSubject === username) && handleDeleteFunction && (
<Group position="right">
{handleEditFunction && (
<Button
onClick={() =>
handleEditFunction({ reviewHTML: review?.reviewHTML, score })
}
color="orange"
variant="light"
mt="sm">
Edit
</Button>
)}
<Button
onClick={() => handleDeleteFunction(id)}
color="orange"
variant="light"
mt="sm">
Delete
</Button>
</Group>
)}
</Card>
);
}
7 changes: 5 additions & 2 deletions apps/film-and-tv-ratings/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useReviewByIdQuery } from '@juxt-home/site';

export function useReviews(imdb_id?: string) {
return useReviewByIdQuery({ imdb_id: imdb_id || '' }, { enabled: !!imdb_id });
export function useReviews(tmdb_id_unique?: string, type = 'movie') {
return useReviewByIdQuery(
{ tmdb_id_unique: `${tmdb_id_unique}` },
{ enabled: !!tmdb_id_unique },
);
}
9 changes: 5 additions & 4 deletions apps/film-and-tv-ratings/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
<html lang="en" class="h-full bg-gray-100">
<head>
<meta charset="utf-8" />
<title>JUXT TV/Film Guild</title>
<base href="/" />

<title>JUXT Film App</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<link
rel="icon"
type="image/x-icon"
href="assets/images/film-app-logo-icon.png" />
</head>
<body class="h-full">
<div id="root"></div>
Expand Down
17 changes: 11 additions & 6 deletions apps/film-and-tv-ratings/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Box } from '@mantine/core';
import 'regenerator-runtime/runtime.js';
import { RecentReviews } from './pages/RecentReviews';
import { newReactLocation } from '@juxt-home/utils';
import { Group } from '@mantine/core';

const reactLocation = newReactLocation();

Expand All @@ -38,13 +39,14 @@ ReactDOM.render(
<QueryClientProvider client={queryClient}>
<Router<NavStructure>
location={reactLocation}
basepath="/_apps/film-and-tv-reviews/app"
routes={[
{
path: '/',
path: 'home',
element: <RecentReviews />,
},
{
path: '/search/:searchType',
path: 'search/:searchType',
element: <SearchResults />,
children: [
{
Expand All @@ -55,7 +57,7 @@ ReactDOM.render(
case 'movie':
return <Movie itemId={itemId} />;
case 'tv':
return <TvShow />;
return <TvShow itemId={itemId} />;
default:
return <Movie itemId={itemId} />;
}
Expand All @@ -71,15 +73,18 @@ ReactDOM.render(
element: <h1>TV page</h1>,
},
{
path: '/*',
path: '*',
element: <p> not found </p>,
},
]}>
<Box sx={{ margin: '3em' }}>
<Box sx={{ marginTop: '3em', height: '100vh' }}>
<Home />
<Outlet />
<Box sx={{ margin: '8.5em 3em', height: '100vh' }}>
<Outlet />
</Box>
</Box>
</Router>

<ToastContainer
position="bottom-center"
autoClose={3000}
Expand Down
71 changes: 54 additions & 17 deletions apps/film-and-tv-ratings/src/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { notEmpty } from '@juxt-home/utils';
import { useState } from 'react';
import { useNavigate } from '@tanstack/react-location';
import { Link, useNavigate } from '@tanstack/react-location';
import { SearchBar, useSearchQuery } from '../components/Search';
import { NavStructure, TSearchResults, TSearchType } from '../types';
import { api_key, client } from '../common';
import { useQuery } from 'react-query';
import { Button, createStyles, Header, Group, Image } from '@mantine/core';

async function fetchSuggestions(query: string) {
const response = await client.get<TSearchResults>(
Expand All @@ -23,36 +24,72 @@ function useSuggestions(query = '') {
);
}

const useStyles = createStyles((theme) => ({
header: {
paddingLeft: theme.spacing.md,
paddingRight: theme.spacing.md,
position: 'fixed',
},

inner: {
height: 120,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
},
}));

export function Home() {
const { classes } = useStyles();

const navigate = useNavigate<NavStructure>();
const [searchType, setSearchType] = useState('movie');

const handleChangeType = (type: TSearchType) => {
setSearchType(type);
navigate({ to: `/search/${type}` });
navigate({ to: `search/${type}` });
};
const handleSubmit = () => {
navigate({
to: `/search/${searchType}`,
to: `search/${searchType}`,
});
};
const [search, setSearch] = useSearchQuery();

return (
<>
<h1>Welcome to the film app</h1>
<button onClick={() => handleChangeType('tv')}>tv</button>
<button onClick={() => handleChangeType('movie')}>movie</button>
<SearchBar
textProps={{
value: search,
data: [],
onChange: setSearch,
placeholder: `Searching for type: ${searchType}`,
}}
handleSubmit={handleSubmit}
/>
</>
<div>
<Header height={120} className={classes.header} mb={120}>
<div className={classes.inner}>
<Link to={'home'}>
<Image height={100} src={'./assets/images/film-app-logo.png'} />
</Link>
<Group>
<Button
color="orange"
variant="light"
onClick={() => handleChangeType('tv')}>
TV
</Button>
<Button
color="orange"
variant="light"
onClick={() => handleChangeType('movie')}>
Movie
</Button>
<SearchBar
textProps={{
value: search,
data: [],
onChange: setSearch,
placeholder: `Searching for type: ${searchType}`,
}}
buttonProps={{ color: 'orange' }}
handleSubmit={handleSubmit}
/>
</Group>
</div>
</Header>
</div>
);
}

Expand Down
Loading