Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
09f6fea
chore: add services to moduleAlias
Darosss Feb 13, 2023
7ad3fa0
chore: update dependecies
Darosss Feb 13, 2023
ce59e2c
config: add services path
Darosss Feb 13, 2023
244f5a1
fix: improve interfaces
Darosss Feb 13, 2023
0f2fdd6
fix: add scope to auth model
Darosss Feb 13, 2023
aa89e74
fix: add default to date
Darosss Feb 13, 2023
3816d22
fix: add twitchId field, and ref "User" to userId
Darosss Feb 13, 2023
3c00558
fix: remove required from some fields
Darosss Feb 13, 2023
01c5aa7
fix: add unique to twitchId and reorder fields
Darosss Feb 13, 2023
da9eef3
fix: add proper module names
Darosss Feb 13, 2023
4835dd0
refactor: move database logic to proper services
Darosss Feb 13, 2023
7c68c9d
feat: add Auth service
Darosss Feb 13, 2023
0475d4c
feat: add ChatCommand service
Darosss Feb 13, 2023
b10f292
feat: add Configs service
Darosss Feb 13, 2023
bdf6d2a
feat: add Message service
Darosss Feb 13, 2023
68b2dc7
feat: add Redemption service
Darosss Feb 13, 2023
2a63be9
feat: add Triggers service
Darosss Feb 13, 2023
5df5d5d
feat: add TwitchSession servie
Darosss Feb 13, 2023
1cf861c
feat: add User service
Darosss Feb 13, 2023
c93f12d
refactor: replace databse logic to proper services
Darosss Feb 13, 2023
6878b83
refactor: replace some fn to proper services
Darosss Feb 13, 2023
b65fa9d
fix: change userData
Darosss Feb 13, 2023
b20ef3b
feat: add retry with catch util
Darosss Feb 13, 2023
78b16eb
refactor: move most of fn to services
Darosss Feb 13, 2023
f02f699
feat: add getAllChatCommands and getOneChatCommand
Darosss Feb 13, 2023
d9629aa
Merge pull request #10 from Darosss/main
Darosss Feb 15, 2023
950a554
feat: add .gitignore
Darosss Feb 16, 2023
7319090
refactor: change way how search params works
Darosss Feb 16, 2023
06610e9
fix: add proper params for pagination and remove unnecessary states
Darosss Feb 16, 2023
9544497
refactor: move whole api calls to service folder
Darosss Feb 16, 2023
b8da820
feat: add Api service
Darosss Feb 16, 2023
1e3ea81
feat: add Auth service
Darosss Feb 16, 2023
8fbe7ee
feat: add Chat command service
Darosss Feb 16, 2023
4cf9ba0
feat: add Config service
Darosss Feb 16, 2023
9d64b7d
feat: add message service
Darosss Feb 16, 2023
350fcfd
feat: add Redemption service
Darosss Feb 16, 2023
6d1e19c
feat: add Trigger service
Darosss Feb 16, 2023
9762287
feat: add Twitch session service
Darosss Feb 16, 2023
798ce03
feat: add User service
Darosss Feb 16, 2023
33bbc86
refactor!: add to every data res.send to data key json
Darosss Feb 16, 2023
05b6eb6
fix: change getOne to createUserIfNotExist
Darosss Feb 16, 2023
adfbafe
refactor: add partial and omit to some interfaces, create type folder
Darosss Feb 16, 2023
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
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#BACKEND
server/dist
server/node_modules


#FRONTEND

# dependencies
frontend/node_modules
frontend/.pnp
frontend/.pnp.js
frontend/public/alert-sounds/*

# testing
/coverage

# production
frontend/dist
frontend/build


npm-debug.log*
yarn-debug.log*
yarn-error.log*



# misc
.DS_Store

.env
.env.local
.env.development.local
.env.test.local
.env.production.local

.vscode

todo.md
11 changes: 1 addition & 10 deletions frontend/src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import React from "react";
import { SocketContext, socketConn } from "@context/SocketContext";
import SideBar from "@components/SideBar";

import { configure } from "axios-hooks";
import Axios from "axios";

import { BrowserRouter, Outlet, Route, Routes } from "react-router-dom";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import TwitchEvents from "@components/TwitchEvents";
import Users from "@components/Users";
import Overlay from "@components/Overlay";
Expand All @@ -19,12 +16,6 @@ import CommandsList from "@components/CommandsList";
import ConfigsList from "@components/ConfigsList";
import TriggersList from "@components/TriggersList";

const axios = Axios.create({
baseURL: import.meta.env.VITE_BACKEND_URL,
});

configure({ axios });

function App() {
return (
<SocketContext.Provider value={socketConn}>
Expand Down
151 changes: 66 additions & 85 deletions frontend/src/components/CommandsList/CommandsList.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import "./style.css";
import { IChatCommand } from "@backend/models/types/";
import Pagination from "@components/Pagination";
import useAxios from "axios-hooks";
import { AxiosRequestConfig } from "axios";
import Modal from "@components/Modal";
import formatDate from "@utils/formatDate";
import PreviousPage from "@components/PreviousPage";
import FilterBarCommands from "./FilterBarCommands";
import { useSearchParams } from "react-router-dom";

interface IChatCommandRes {
chatCommands: IChatCommand[];
totalPages: number;
count: number;
currentPage: number;
}
import ChatCommandService from "src/services/Chat-command.service";

export default function CommandsList() {
const [searchParams] = useSearchParams();

const [currentPageLoc, setCurrentPageLoc] = useState(1);

const [pageSize, setPageSize] = useState(
Number(localStorage.getItem("commandsListPageSize")) || 15
);

const [showModal, setShowModal] = useState(false);

const [editingCommand, setEditingCommand] = useState("");
const [commandIdDelete, setCommandIdDelete] = useState<string | null>(null);

const [name, setName] = useState("");
const [description, setDescription] = useState("");
Expand All @@ -37,65 +20,60 @@ export default function CommandsList() {
const [messages, setMessages] = useState([""]);
const [privilege, setPrivilege] = useState<number>();

const [{ data, loading, error }, refetchCommands] = useAxios<IChatCommandRes>(
`/chat-commands?page=${currentPageLoc}&limit=${pageSize}&${searchParams}`
);
const {
data: commandsData,
loading,
error,
refetchData,
} = ChatCommandService.getCommands();

useEffect(() => {
if (
commandIdDelete !== null &&
confirm(`Are you sure you want to delete command: ${commandIdDelete}?`)
) {
fetchDeleteCommand().then(() => {
refetchData();
setCommandIdDelete(null);
});
} else {
setCommandIdDelete(null);
}
}, [commandIdDelete]);

const [{}, postChatCommand] = useAxios<{
message: string;
}>(
const { refetchData: fetchEditComman } = ChatCommandService.editCommand(
editingCommand,
{
method: "POST",
} as AxiosRequestConfig,
{ manual: true }
name: name,
description: description,
enabled: enabled,
aliases: aliases,
messages: messages,
privilege: privilege || 0,
}
);

if (error) return <>There is an error. {error.response?.data.message}</>;
if (loading || !data) return <> Loading...</>;
const { refetchData: fetchCreateCommand } = ChatCommandService.createCommand({
name: `New command${commandsData?.count}`,
description: `New command description${commandsData?.count}`,
enabled: true,
aliases: [`New command${commandsData?.count} default alias`],
messages: [`New command${commandsData?.count} default message`],
privilege: 0,
});

const { chatCommands, count, currentPage } = data;
const { refetchData: fetchDeleteCommand } = ChatCommandService.deleteCommand(
commandIdDelete ? commandIdDelete : ""
);

const removeCommand = (id: string) => {
if (confirm(`Are you sure you want delete command: }`))
postChatCommand({
url: `/chat-commands/delete/${id}`,
method: "DELETE",
} as AxiosRequestConfig).then(() => {
refetchCommands();
});
};
if (error) return <>There is an error. {error.response?.data.message}</>;
if (loading || !commandsData) return <> Loading...</>;

const createNewCommand = () => {
postChatCommand({
url: `/chat-commands/create`,
method: "POST",
data: {
name: `New command${count}`,
description: `New command description${count}`,
enabled: true,
aliases: [`New command${count} default alias`],
messages: [`New command${count} default message`],
privilege: 0,
},
} as AxiosRequestConfig).then(() => {
refetchCommands();
});
};
const { data, count, currentPage } = commandsData;

const editCommand = () => {
postChatCommand({
url: `/chat-commands/${editingCommand}`,
method: "POST",
data: {
name: name,
description: description,
enabled: enabled,
aliases: aliases,
messages: messages,
privilege: privilege,
},
} as AxiosRequestConfig).then(() => {
refetchCommands();
const createNewCommand = () => {
fetchCreateCommand().then(() => {
refetchData();
});
};

Expand All @@ -120,6 +98,19 @@ export default function CommandsList() {
});
};

const onSubmitEditModal = () => {
fetchEditComman().then(() => {
refetchData();
});
resetOnChangeClasses();
setShowModal(false);
};

const onCloseModal = () => {
setShowModal(false);
resetOnChangeClasses();
};

return (
<>
<PreviousPage />
Expand Down Expand Up @@ -150,7 +141,7 @@ export default function CommandsList() {
</thead>

<tbody>
{chatCommands.map((command) => {
{data.map((command) => {
return (
<tr key={command._id}>
<td>
Expand All @@ -171,7 +162,7 @@ export default function CommandsList() {
</button>
<button
className="command-action command-list-button command-delete"
onClick={(e) => removeCommand(command._id)}
onClick={() => setCommandIdDelete(command._id)}
>
Delete
</button>
Expand Down Expand Up @@ -207,23 +198,13 @@ export default function CommandsList() {
localStorageName="commandsListPageSize"
currentPage={currentPage}
totalCount={count}
pageSize={pageSize}
onPageSizeChange={(pageSize) => setPageSize(pageSize)}
onPageChange={(page) => setCurrentPageLoc(page)}
siblingCount={1}
/>
</div>
<Modal
title="Edit command"
onClose={() => {
setShowModal(false);
resetOnChangeClasses();
}}
onSubmit={() => {
editCommand();
resetOnChangeClasses();
setShowModal(false);
}}
onClose={() => onCloseModal()}
onSubmit={() => onSubmitEditModal()}
show={showModal}
>
<table className="commands-list-modal-wrapper">
Expand Down
60 changes: 22 additions & 38 deletions frontend/src/components/ConfigsList/ConfigsList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React, { useReducer, useState } from "react";
import React, { useState } from "react";
import "./style.css";
import useAxios from "axios-hooks";

import PreviousPage from "@components/PreviousPage";
import { AxiosRequestConfig } from "axios";
import { IConfig } from "@backend/models/types";
import ConfigService from "src/services/Config.service";

export default function UserProfile() {
const [showEdit, setShowEdit] = useState(false);
Expand All @@ -21,33 +18,16 @@ export default function UserProfile() {
all: 0,
});

const [
{ data: configsData, loading: configsLoading, error: configsError },
refetchConfigs,
] = useAxios<IConfig>(`/configs`);

const [, executeSaveConfig] = useAxios(
{
url: `/configs/edit`,
method: "POST",
} as AxiosRequestConfig,
{ manual: true }
);
const { data, loading, error, refetchData } = ConfigService.getConfigs();

const saveConfig = () => {
executeSaveConfig({
data: {
commandsPrefix: prefix,
timersIntervalDelay: timersInterval,
activeUserTimeDelay: activeUserTime,
chatGamesIntervalDelay: chatGamesInterval,
minActiveUsersThreshold: minActiveUsers,
permissionLevels: permissions,
},
} as AxiosRequestConfig).then(() => {
refetchConfigs();
});
};
const { refetchData: fetchEditConfig } = ConfigService.editConfig({
commandsPrefix: prefix,
timersIntervalDelay: timersInterval,
activeUserTimeDelay: activeUserTime,
chatGamesIntervalDelay: chatGamesInterval,
minActiveUsersThreshold: minActiveUsers,
permissionLevels: permissions,
});

const setConfigStates = () => {
setPrefix(commandsPrefix);
Expand All @@ -58,8 +38,15 @@ export default function UserProfile() {
setPermissions(permissionLevels);
};

if (configsError) return <>There is an error.</>;
if (!configsData || configsLoading) return <>Someting went wrong</>;
const onClickEditConfig = () => {
setShowEdit(false);
fetchEditConfig().then(() => {
refetchData();
});
};

if (error) return <>There is an error.</>;
if (!data || loading) return <>Someting went wrong</>;

const {
commandsPrefix,
Expand All @@ -68,7 +55,7 @@ export default function UserProfile() {
chatGamesIntervalDelay,
minActiveUsersThreshold,
permissionLevels,
} = configsData;
} = data;

return (
<>
Expand All @@ -87,10 +74,7 @@ export default function UserProfile() {
{showEdit ? (
<button
className="edit-config-button"
onClick={() => {
setShowEdit(false);
saveConfig();
}}
onClick={() => onClickEditConfig()}
>
Save
</button>
Expand Down
Loading