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