1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-08-06 03:15:18 +02:00

Fetch and use custom search queries

This commit is contained in:
unknown 2021-10-06 14:15:05 +02:00
parent da928f20a2
commit 591824dd0c
9 changed files with 136 additions and 80 deletions

View file

@ -1,7 +1,7 @@
import axios from 'axios';
import { Dispatch } from 'redux';
import { ActionTypes } from './actionTypes';
import { Config, ApiResponse } from '../../interfaces';
import { Config, ApiResponse, Query } from '../../interfaces';
import { CreateNotificationAction } from './notification';
import { searchConfig } from '../../utility';
@ -13,18 +13,18 @@ export interface GetConfigAction {
export const getConfig = () => async (dispatch: Dispatch) => {
try {
const res = await axios.get<ApiResponse<Config[]>>('/api/config');
dispatch<GetConfigAction>({
type: ActionTypes.getConfig,
payload: res.data.data
})
payload: res.data.data,
});
// Set custom page title if set
document.title = searchConfig('customTitle', 'Flame');
} catch (err) {
console.log(err)
console.log(err);
}
}
};
export interface UpdateConfigAction {
type: ActionTypes.updateConfig;
@ -34,19 +34,41 @@ export interface UpdateConfigAction {
export const updateConfig = (formData: any) => async (dispatch: Dispatch) => {
try {
const res = await axios.put<ApiResponse<Config[]>>('/api/config', formData);
dispatch<CreateNotificationAction>({
type: ActionTypes.createNotification,
payload: {
title: 'Success',
message: 'Settings updated'
}
})
message: 'Settings updated',
},
});
dispatch<UpdateConfigAction>({
type: ActionTypes.updateConfig,
payload: res.data.data
})
payload: res.data.data,
});
} catch (err) {
console.log(err);
}
}
};
export interface FetchQueriesAction {
type: ActionTypes.fetchQueries;
payload: Query[];
}
export const fetchQueries =
() => async (dispatch: Dispatch<FetchQueriesAction>) => {
try {
const res = await axios.get<ApiResponse<Query[]>>(
'/api/config/0/queries'
);
dispatch<FetchQueriesAction>({
type: ActionTypes.fetchQueries,
payload: res.data.data,
});
} catch (err) {
console.log(err);
}
};