Skip to content

Commit

Permalink
WIP frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha committed Jul 26, 2023
1 parent bd2a9e1 commit 3c6eada
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 34 deletions.
21 changes: 1 addition & 20 deletions assets/component/appbar/AppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,7 @@ function ResponsiveAppBar() {
textDecoration: 'none',
}}
>
LOGO
</Typography>
<AdbIcon sx={{ display: { xs: 'flex', md: 'none' }, mr: 1 }} />
<Typography
variant="h5"
noWrap
component="a"
href=""
sx={{
mr: 2,
display: { xs: 'flex', md: 'none' },
flexGrow: 1,
fontFamily: 'monospace',
fontWeight: 700,
letterSpacing: '.3rem',
color: 'inherit',
textDecoration: 'none',
}}
>
LOGO
EMPR
</Typography>
<Box sx={{ flexGrow: 1, display: { xs: 'none', md: 'flex' } }}>
<MenuItem key='development' onClick={() => navigate("/development")}>
Expand Down
33 changes: 27 additions & 6 deletions assets/page/FilmsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Container} from "@mui/material";
import {Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow} from "@mui/material";
import {BasePage} from "./BasePage";
import apiService, {FilmResponse} from "../services/ApiService";
import {useEffect, useState} from "react";
import {mapFilmType} from "../services/ReadableStringMapper";

export const FilmsPage = () => {
const [films, setFilms] = useState<FilmResponse[]>([]);
Expand All @@ -12,11 +13,31 @@ export const FilmsPage = () => {

return (
<BasePage>
<Container>
<ol>
{films.map((film) => <li key={film.id}>{film.name}</li>)}
</ol>
</Container>
<Paper elevation={0} variant="outlined" square sx={{marginTop: '10px', padding: '5px'}}>
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell align="left">Name</TableCell>
<TableCell align="left">Type</TableCell>
<TableCell align="left">Speed (ISO/ASA)</TableCell>
</TableRow>
</TableHead>
<TableBody>
{films.map((row) => (
<TableRow
key={row.id}
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
>
<TableCell align="left">{row.name}</TableCell>
<TableCell align="left">{mapFilmType(row.type)}</TableCell>
<TableCell align="left">{row.speed}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</Paper>
</BasePage>
);
}
4 changes: 1 addition & 3 deletions assets/page/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ export const MainPage = () => {
<BasePage>
<Container>
<Paper elevation={0} variant="outlined" square sx={{marginTop: '10px', padding: '5px'}}>
<Paper elevation={0} variant="outlined" square sx={{marginTop: '10px', padding: '5px'}}>
TEST
</Paper>
TEST
</Paper>
</Container>
</BasePage>
Expand Down
6 changes: 5 additions & 1 deletion assets/services/ApiService.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import axios from './axios';
import {AxiosError, AxiosResponse} from "axios";
import {Method} from "axios/index";
import {Method} from "axios";
import {useUser} from "./auth/useUser";

export interface LoginResponse {
token: string,
refreshToken: string,
}

export type FilmType = 'bw' | 'color_negative' | 'color_positive';

export interface FilmResponse {
id: string,
name: string,
type: FilmType,
speed: number,
}

export class ApiService {
Expand Down
11 changes: 11 additions & 0 deletions assets/services/ReadableStringMapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {FilmType} from "./ApiService";

export function mapFilmType(type: FilmType): string {
switch (type) {
case "bw": return 'Black and white';
case "color_negative": return 'Color Negative';
case "color_positive": return 'Diapositive';
}

throw new Error("Unknown film type");
}
4 changes: 3 additions & 1 deletion assets/services/auth/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ export const useAuth = () => {
setUser({username: username, token: token, refreshToken: refreshToken});
};

const refreshToken = async () => {
const refreshToken = async (): Promise<string> => {
const {token, refreshToken} = await api.refreshToken(getUser().refreshToken);
updateUser({token: token, refreshToken: refreshToken});

return token;
}

const logout = async () => {
Expand Down
4 changes: 2 additions & 2 deletions assets/services/axios.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Axios from "axios";
import { API_SERVER } from "./constants";
import {useUser} from "./auth/useUser";
import {useAuth} from "./auth/useAuth";

const axios = Axios.create({
Expand All @@ -25,8 +24,9 @@ axios.interceptors.response.use(

try {
const {refreshToken} = useAuth();
await refreshToken();
const newToken = await refreshToken();

config.headers['Authorization'] = 'Bearer ' + newToken;
return axios(config);
} catch (e) {
return Promise.reject(error);
Expand Down
3 changes: 2 additions & 1 deletion src/Entity/Film/Film.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
new GetCollection(provider: FilmCollectionProvider::class),
new Post(security: "is_granted('ROLE_CREATE_FILMS')", input: FilmCreateDto::class, processor: CreateFilmProcessor::class),
],
output: FilmOutputDto::class
output: FilmOutputDto::class,
order: ['name' => 'ASC'],
)]
#[UniqueEntity(fields: ['name'])]
class Film
Expand Down

0 comments on commit 3c6eada

Please sign in to comment.