mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 05:59:45 +00:00
8 files changed
+67
-32
No files matched your search
@@ -21,3 +21,6 @@
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
#copies
|
||||
*.copy
|
||||
@@ -16,4 +16,4 @@ React-приложение "Сайт СКБ КИТ" для использова
|
||||
- поместить папку проекта в директорию /*wordpress-dir*/wp-content/reactpress/apps
|
||||
- перейти в папку проекта
|
||||
- установить необходимые библиотеки (npm install)
|
||||
- запустить dev-build (npm start) или собрать приложение (npm run build) и открыть страницу в wordpress
|
||||
- запустить dev-build (npm start) или собрать приложение (npm run build) и открыть страницу в wordpress
|
||||
+31
-15
@@ -2,8 +2,6 @@ import * as WPAPI from 'wpapi';
|
||||
|
||||
import reactPress from './reactPress';
|
||||
|
||||
const fbToken = 'ltvszr1EL7Q8lX9v4W7ivAEwJsFUvicFGtLepCDj';
|
||||
|
||||
const wp = new WPAPI(
|
||||
process.env.NODE_ENV === 'development'
|
||||
? {
|
||||
@@ -13,19 +11,39 @@ const wp = new WPAPI(
|
||||
}
|
||||
: { endpoint: reactPress.api.rest_url, nonce: reactPress.api.nonce }
|
||||
);
|
||||
wp.setHeaders('Authorization', 'Bearer ' + fbToken);
|
||||
|
||||
// Получаем категории медиафайлов
|
||||
const response = await wp.url(reactPress.api.rest_url + 'filebird/public/v1/folders')
|
||||
const { data: { folders } } = response;
|
||||
const mediaCategories = {};
|
||||
// Функция загрузки медабиблиотеки по категориям
|
||||
async function loadMedia() {
|
||||
// Пытаемся получить медиа, пока не получится
|
||||
let response;
|
||||
while (!response) {
|
||||
try {
|
||||
response = await wp.media();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Деструктурируем объекты в формат {category: id}
|
||||
for (let { id, text } of folders) {
|
||||
mediaCategories[text] = id;
|
||||
// Нам потребуется id, категория и url
|
||||
const result = {};
|
||||
for (let { id, alt_text, source_url: url } of response) {
|
||||
const [category, name] = alt_text.split('_');
|
||||
|
||||
// Создаем ключ с пустым массивом, если еще нет
|
||||
if (!result[category]) {
|
||||
result[category] = [];
|
||||
}
|
||||
|
||||
// Добавляем медиа в массив нужной категории
|
||||
result[category].push({ id, name, url });
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
console.log(response);
|
||||
console.log(mediaCategories);
|
||||
|
||||
const mediaLibrary = await loadMedia();
|
||||
console.log(mediaLibrary);
|
||||
|
||||
export async function getPosts(q = '') {
|
||||
try {
|
||||
const posts = await wp.posts().search(q);
|
||||
@@ -38,9 +56,7 @@ export async function getPosts(q = '') {
|
||||
|
||||
export async function getMedia(category) {
|
||||
try {
|
||||
const response = await wp.url(reactPress.api.rest_url + 'filebird/public/v1/attachment-id/?folder_id=' + mediaCategories[category]);
|
||||
console.log(response);
|
||||
return [];
|
||||
return mediaLibrary[category];
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return [];
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
import FooterLink from './FooterLink';
|
||||
import FooterContacts from './FooterContacts';
|
||||
import { getMedia } from '../../api';
|
||||
|
||||
import { scb as logo } from '../../assets/images';
|
||||
import { iconIctis, iconSfedu, iconVK } from '../../assets/images/footer';
|
||||
import './Footer.styles.scss';
|
||||
import FooterContacts from './FooterContacts';
|
||||
|
||||
const mockLinks = [
|
||||
{
|
||||
const mockLinks = {
|
||||
ictis: {
|
||||
icon: iconIctis,
|
||||
to: "https://ictis.sfedu.ru",
|
||||
},
|
||||
{
|
||||
sfedu: {
|
||||
icon: iconSfedu,
|
||||
to: "https://sfedu.ru",
|
||||
},
|
||||
{
|
||||
vk: {
|
||||
icon: iconVK,
|
||||
to: "https://vk.com/skbkit",
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
const mockContacts = {
|
||||
email: "skb@sfedu.ru",
|
||||
@@ -26,6 +30,22 @@ const mockContacts = {
|
||||
};
|
||||
|
||||
function Footer({ links = mockLinks, contacts = mockContacts }) {
|
||||
const [mediaList, setMediaList] = useState(links);
|
||||
|
||||
useEffect(() => {
|
||||
const loadData = async () => {
|
||||
const footerMedia = await getMedia('footer');
|
||||
const newMediaList = mediaList;
|
||||
|
||||
for (let media of footerMedia) {
|
||||
newMediaList[media.name].icon = media.url;
|
||||
}
|
||||
|
||||
setMediaList(newMediaList);
|
||||
};
|
||||
loadData();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<footer className="footer">
|
||||
<div className="logo-container">
|
||||
@@ -33,7 +53,7 @@ function Footer({ links = mockLinks, contacts = mockContacts }) {
|
||||
</div>
|
||||
<FooterContacts contacts={ contacts } />
|
||||
<div className="links">
|
||||
{ links.map((link, index) => <FooterLink link={link} key={index} />) }
|
||||
{ Object.keys(mediaList).forEach((link, index) => <FooterLink link={link} key={index} />) }
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
|
||||
@@ -15,7 +15,7 @@ function Slider({ autoPlay = 0, autoPlayTime = 0 }) {
|
||||
|
||||
useEffect(() => {
|
||||
const loadData = async () => {
|
||||
const newMediaList = await getMedia('CATEGORY');
|
||||
const newMediaList = await getMedia('gallery');
|
||||
setMediaList(newMediaList);
|
||||
};
|
||||
loadData();
|
||||
|
||||
@@ -18,15 +18,11 @@
|
||||
|
||||
& .slide-image {
|
||||
display: flex;
|
||||
height: 60vh;
|
||||
max-height: 60vh;
|
||||
max-width: calc(100% - 2 * (15% + 30px));
|
||||
margin: 0 auto;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
& .slide-title {
|
||||
text-align: center;
|
||||
margin-top: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ export default function SlidesList() {
|
||||
style={{ transform: `translateX(-${slideNumber * 100}%)` }}
|
||||
>
|
||||
{mediaList.map((slide, index) => (
|
||||
<Slide key={index} slide={slide.source_url} />
|
||||
<Slide key={index} slide={slide.url} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { createContext, useEffect } from 'react';
|
||||
import { getMedia } from "../../api";
|
||||
import useElementOnScreen from '../../lib/useElementOnScreen';
|
||||
import Navbar from '../../components/Navbar';
|
||||
import Footer from "../../components/Footer";
|
||||
import Footer from '../../components/Footer';
|
||||
import './Root.styles.scss';
|
||||
|
||||
export const RootContext = createContext();
|
||||
|
||||
Reference in new issue
Block a user