Skip to content

Commit

Permalink
Merge pull request #15 from antonKrizmanic/stage
Browse files Browse the repository at this point in the history
Stage
  • Loading branch information
antonKrizmanic authored Oct 13, 2024
2 parents c9ca2ce + 9b95312 commit b5dc08a
Show file tree
Hide file tree
Showing 61 changed files with 1,248 additions and 1,668 deletions.
5 changes: 2 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": [
"next/core-web-vitals",
"plugin:storybook/recommended",
"next/core-web-vitals",
"plugin:import/recommended",
"plugin:import/typescript"
],
Expand Down Expand Up @@ -33,7 +32,7 @@
"react/jsx-props-no-multi-spaces": "error",
"react/jsx-wrap-multilines": "error",
"semi": [2, "always"],
"indent": ["error", 2],
"indent": ["error", 4],
"quotes": ["error", "single"],
"jsx-quotes": ["error", "prefer-double"],
"comma-dangle": ["error", "never"],
Expand Down
34 changes: 0 additions & 34 deletions .github/workflows/deploy.yml

This file was deleted.

76 changes: 38 additions & 38 deletions app-models/UserAppModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,81 +10,81 @@ import User from '@/models/User';
* @class UserAppModel
*/
export default class UserAppModel {
/**
/**
* Instance of the app model.
*
* @static
* @memberof UserAppModel
*/
static _appModel: UserAppModel = null;
static _appModel: UserAppModel = null;

/**
/**
* Returns the app model's instance.
*
* @static
* @returns app model's instance
* @memberof UserAppModel
*/
static get instance() {
static get instance() {
// Creates instance if it isn't set yet
if (UserAppModel._appModel === null) {
UserAppModel._appModel = new UserAppModel();
}
if (UserAppModel._appModel === null) {
UserAppModel._appModel = new UserAppModel();
}

return UserAppModel._appModel;
}
return UserAppModel._appModel;
}

/**
/**
* User.
*
* @memberof UserAppModel
*/
user: User;
user: User;

/**
/**
* Creates an instance of UserAppModel.
*
* @memberof UserAppModel
*/
constructor() {
this.user = null;
constructor() {
this.user = null;

makeObservable(this, {
user: observable,
loadUser: action.bound,
editUser: action.bound
});
}
makeObservable(this, {
user: observable,
loadUser: action.bound,
editUser: action.bound
});
}

/**
/**
* Loads the user.
*
* @memberof UserAppModel
*/
loadUser() {
try {
this.user = getUser();
} catch (e) {
console.error(e);
showDefaultErrorNotification();
loadUser() {
try {
this.user = getUser();
} catch (e) {
console.error(e);
showDefaultErrorNotification();
}
}
}

/**
/**
* Edits the user.
*
* @param name Name
* @memberof UserAppModel
*/
editUser(name: string) {
try {
const payload = this.user ? this.user.clone() : new User();
payload.name = name;
editUser(name: string) {
try {
const payload = this.user ? this.user.clone() : new User();
payload.name = name;

this.user = editUser(payload);
} catch (e) {
console.error(e);
showDefaultErrorNotification();
this.user = editUser(payload);
} catch (e) {
console.error(e);
showDefaultErrorNotification();
}
}
}
}
36 changes: 16 additions & 20 deletions app/(routes)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
'use client';

import { Button, Stack, Typography } from '@mui/material';
import { useRouter } from 'next/navigation';
import { useState } from 'react';
import { Button, Stack, Typography } from '@mui/material';

const HomePage = () => {
const router = useRouter();
const [selectedTheme, setSelectedTheme] = useState<string | null>(null);
function HomePage() {
const router = useRouter();

const handleThemeSelection = (theme: string) => {
setSelectedTheme(theme);
router.push(`/categories?theme=${theme}`);
};
const handleThemeSelection = (theme: string) => {
router.push(`/categories?theme=${theme}`);
};

return (
<>
<Typography variant="h1" gutterBottom>Odaberite temu kviza</Typography>

<Stack spacing={1}>
<Button onClick={() => handleThemeSelection('100')} variant="outlined">Prva pomoć</Button>
<Button onClick={() => handleThemeSelection('200')} variant="outlined">Pokret Crvenog križa</Button>
</Stack>
</>
);
};
return (
<>
<Typography variant="h1" gutterBottom>Odaberite temu kviza</Typography>
<Stack spacing={1}>
<Button onClick={() => handleThemeSelection('100')} variant="outlined">Prva pomoć</Button>
<Button onClick={() => handleThemeSelection('200')} variant="outlined">Pokret Crvenog križa</Button>
</Stack>
</>
);
}

export default HomePage;
108 changes: 56 additions & 52 deletions app/categories/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use client';

import { useRouter, useSearchParams } from 'next/navigation';
import { useEffect, useState } from 'react';
import { get } from '../../services/HttpService';
import { useRouter, useSearchParams } from 'next/navigation';
import { Button, Stack, Typography } from '@mui/material';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faArrowLeft } from '@fortawesome/free-solid-svg-icons';

import { get } from '../../services/HttpService';

interface Category {
id: number;
name: string;
Expand All @@ -15,62 +16,65 @@ interface Category {
description: string | null;
}

const CategoriesPage = () => {
const router = useRouter();
const searchParams = useSearchParams();
const theme = searchParams.get('theme');
const [categories, setCategories] = useState<Category[]>([]);
const [loading, setLoading] = useState<boolean>(true);
function CategoriesPage() {
const router = useRouter();
const searchParams = useSearchParams();
const theme = searchParams.get('theme');
const [categories, setCategories] = useState<Category[]>([]);
const [loading, setLoading] = useState<boolean>(true);

useEffect(() => {
const fetchCategories = async () => {
try {
const response = await get(`Quizzes/PublicQuizCategory/GetList/1?QuizTheme=${theme}&ActiveStatusId=1&Page=0&SearchTerm=&Type=&Field=&IgnorePageSize=True&PerPage=10`);
setCategories(response.data.list);
} catch (error) {
console.error('Error fetching categories:', error);
} finally {
setLoading(false);
}
};
useEffect(() => {
const fetchCategories = async () => {
try {
// eslint-disable-next-line max-len
const response = await get(`Quizzes/PublicQuizCategory/GetList/1?QuizTheme=${theme}&ActiveStatusId=1&Page=0&SearchTerm=&Type=&Field=&IgnorePageSize=True&PerPage=10`);
setCategories(response.data.list);
} catch (error) {
console.error('Error fetching categories:', error);
} finally {
setLoading(false);
}
};

if (theme) {
fetchCategories();
}
}, [theme]);
if (theme) {
fetchCategories();
}
}, [theme]);

const handleCategorySelection = (category: string) => {
router.push(`/init-quiz?theme=${theme}&category=${category}`);
};
const handleCategorySelection = (category: string) => {
router.push(`/init-quiz?theme=${theme}&category=${category}`);
};

const handleBack = () => {
router.back();
};
const handleBack = () => {
router.back();
};

if (loading) {
return <div>Loading...</div>;
}
if (loading) {
return <div>Loading...</div>;
}

return (
<>
<Typography variant="h1" gutterBottom>Odaberite kategoriju kviza</Typography>
<Stack spacing={1} sx={{marginBottom:3}}>
{categories.length === 0 ? (
<Typography>Nije dohvaćena ni jedna kategorija</Typography>
) : (
categories.map((category) => (
<Button onClick={() => handleCategorySelection(category.id.toString())} variant="outlined" key={category.id}>
{category.name}
</Button>
))
)}
<Button onClick={handleBack} variant="outlined">
<FontAwesomeIcon icon={faArrowLeft} /> &nbsp;
return (
<>
<Typography variant="h1" gutterBottom>Odaberite kategoriju kviza</Typography>
<Stack spacing={1} sx={{marginBottom:3}}>
{categories.length === 0 ? (
<Typography>Nije dohvaćena ni jedna kategorija</Typography>
) : (
categories.map((category) => (
<Button onClick={() => handleCategorySelection(category.id.toString())}
variant="outlined"
key={category.id}>
{category.name}
</Button>
))
)}
<Button onClick={handleBack} variant="outlined">
<FontAwesomeIcon icon={faArrowLeft} /> &nbsp;
Natrag
</Button>
</Stack>
</>
);
};
</Button>
</Stack>
</>
);
}

export default CategoriesPage;
2 changes: 1 addition & 1 deletion app/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import InternalServerError from '@/views/InternalServerErrorView/InternalServerE
* @returns ErrorPage component
*/
export default function ErrorPage() {
return <InternalServerError />;
return <InternalServerError />;
}
Loading

0 comments on commit b5dc08a

Please sign in to comment.