mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-26 06:19:36 +02:00
parent
beec2485d5
commit
c80e4257ff
4 changed files with 41 additions and 38 deletions
|
@ -25,7 +25,7 @@ interface ComponentProps {
|
||||||
|
|
||||||
export enum ContentType {
|
export enum ContentType {
|
||||||
category,
|
category,
|
||||||
app,
|
app
|
||||||
}
|
}
|
||||||
|
|
||||||
const Apps = (props: ComponentProps): JSX.Element => {
|
const Apps = (props: ComponentProps): JSX.Element => {
|
||||||
|
@ -34,26 +34,24 @@ const Apps = (props: ComponentProps): JSX.Element => {
|
||||||
const [modalIsOpen, setModalIsOpen] = useState(false);
|
const [modalIsOpen, setModalIsOpen] = useState(false);
|
||||||
const [formContentType, setFormContentType] = useState(ContentType.category);
|
const [formContentType, setFormContentType] = useState(ContentType.category);
|
||||||
const [isInEdit, setIsInEdit] = useState(false);
|
const [isInEdit, setIsInEdit] = useState(false);
|
||||||
const [tableContentType, setTableContentType] = useState(
|
const [tableContentType, setTableContentType] = useState(ContentType.category);
|
||||||
ContentType.category
|
|
||||||
);
|
|
||||||
const [isInUpdate, setIsInUpdate] = useState(false);
|
const [isInUpdate, setIsInUpdate] = useState(false);
|
||||||
const [categoryInUpdate, setCategoryInUpdate] = useState<Category>({
|
const [categoryInUpdate, setCategoryInUpdate] = useState<Category>({
|
||||||
name: "",
|
name: '',
|
||||||
id: -1,
|
id: -1,
|
||||||
isPinned: false,
|
isPinned: false,
|
||||||
orderId: 0,
|
orderId: 0,
|
||||||
type: "apps",
|
type: 'apps',
|
||||||
apps: [],
|
apps: [],
|
||||||
bookmarks: [],
|
bookmarks: [],
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date()
|
||||||
});
|
})
|
||||||
const [appInUpdate, setAppInUpdate] = useState<App>({
|
const [appInUpdate, setAppInUpdate] = useState<App>({
|
||||||
name: "string",
|
name: 'string',
|
||||||
url: "string",
|
url: 'string',
|
||||||
categoryId: -1,
|
categoryId: -1,
|
||||||
icon: "string",
|
icon: 'string',
|
||||||
isPinned: false,
|
isPinned: false,
|
||||||
orderId: 0,
|
orderId: 0,
|
||||||
id: 0,
|
id: 0,
|
||||||
|
|
|
@ -191,9 +191,7 @@ const BookmarkTable = (props: ComponentProps): JSX.Element => {
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={classes.TableAction}
|
className={classes.TableAction}
|
||||||
onClick={() =>
|
onClick={() => props.pinBookmarkCategory(category)}
|
||||||
props.pinBookmarkCategory(category)
|
|
||||||
}
|
|
||||||
onKeyDown={(e) =>
|
onKeyDown={(e) =>
|
||||||
keyboardActionHandler(
|
keyboardActionHandler(
|
||||||
e,
|
e,
|
||||||
|
|
|
@ -138,30 +138,29 @@ export interface AddAppAction {
|
||||||
payload: App;
|
payload: App;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const addApp =
|
export const addApp = (formData: NewApp | FormData) => async (dispatch: Dispatch) => {
|
||||||
(formData: NewApp | FormData) => async (dispatch: Dispatch) => {
|
try {
|
||||||
try {
|
const res = await axios.post<ApiResponse<App>>("/api/apps", formData);
|
||||||
const res = await axios.post<ApiResponse<App>>("/api/apps", formData);
|
|
||||||
|
|
||||||
dispatch<CreateNotificationAction>({
|
dispatch<CreateNotificationAction>({
|
||||||
type: ActionTypes.createNotification,
|
type: ActionTypes.createNotification,
|
||||||
payload: {
|
payload: {
|
||||||
title: "Success",
|
title: "Success",
|
||||||
message: `App ${res.data.data.name} added`,
|
message: `App ${res.data.data.name} added`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await dispatch<AddAppAction>({
|
await dispatch<AddAppAction>({
|
||||||
type: ActionTypes.addAppSuccess,
|
type: ActionTypes.addAppSuccess,
|
||||||
payload: res.data.data,
|
payload: res.data.data,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sort apps
|
// Sort apps
|
||||||
dispatch<any>(sortApps());
|
dispatch<any>(sortApps());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PIN CATEGORY
|
* PIN CATEGORY
|
||||||
|
|
|
@ -88,9 +88,7 @@ const pinCategory = (state: State, action: Action): State => {
|
||||||
|
|
||||||
const pinApp = (state: State, action: Action): State => {
|
const pinApp = (state: State, action: Action): State => {
|
||||||
const tmpApps = [...state.apps];
|
const tmpApps = [...state.apps];
|
||||||
const changedApp = tmpApps.find(
|
const changedApp = tmpApps.find((app: App) => app.id === action.payload.id);
|
||||||
(app: App) => app.id === action.payload.id
|
|
||||||
);
|
|
||||||
|
|
||||||
if (changedApp) {
|
if (changedApp) {
|
||||||
changedApp.isPinned = action.payload.isPinned;
|
changedApp.isPinned = action.payload.isPinned;
|
||||||
|
@ -245,6 +243,16 @@ const reorderApps = (state: State, action: Action): State => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const sortApps = (state: State, action: Action): State => {
|
const sortApps = (state: State, action: Action): State => {
|
||||||
|
// const tmpCategories = [...state.categories];
|
||||||
|
|
||||||
|
// tmpCategories.forEach((category: Category) => {
|
||||||
|
// category.apps = sortData<App>(category.apps, action.payload);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// ...state,
|
||||||
|
// categories: tmpCategories,
|
||||||
|
// };
|
||||||
const sortedApps = sortData<App>(state.apps, action.payload);
|
const sortedApps = sortData<App>(state.apps, action.payload);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue