From 981b83cea280d2247ab9c45df74bb4bf57a01607 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Tue, 7 Feb 2023 10:05:03 +0530 Subject: [PATCH] wip jam-ui new session window --- .../components/dashboard/JKDashboardMain.js | 2 +- jam-ui/src/components/page/JKMusicSessions.js | 2 +- .../src/components/page/JKNewMusicSession.js | 120 +++++++++++++++++- jam-ui/src/helpers/rest.js | 8 ++ 4 files changed, 124 insertions(+), 8 deletions(-) diff --git a/jam-ui/src/components/dashboard/JKDashboardMain.js b/jam-ui/src/components/dashboard/JKDashboardMain.js index 3cd7eec1f..b0311d272 100644 --- a/jam-ui/src/components/dashboard/JKDashboardMain.js +++ b/jam-ui/src/components/dashboard/JKDashboardMain.js @@ -178,8 +178,8 @@ function JKDashboardMain() { - + {/*Redirect*/} diff --git a/jam-ui/src/components/page/JKMusicSessions.js b/jam-ui/src/components/page/JKMusicSessions.js index 756e1120a..59b0d1bb3 100644 --- a/jam-ui/src/components/page/JKMusicSessions.js +++ b/jam-ui/src/components/page/JKMusicSessions.js @@ -2,7 +2,7 @@ import React from 'react' function JKMusicSessions() { return ( -
JKMusicSessions
+
Music Sessions Listing
) } diff --git a/jam-ui/src/components/page/JKNewMusicSession.js b/jam-ui/src/components/page/JKNewMusicSession.js index ddceda12e..08d23125d 100644 --- a/jam-ui/src/components/page/JKNewMusicSession.js +++ b/jam-ui/src/components/page/JKNewMusicSession.js @@ -1,9 +1,117 @@ -import React from 'react' +import React, { useState } from 'react'; +import { Form, FormGroup, Input, Label, Text, Card, CardBody, Button } from 'reactstrap'; +import FalconCardHeader from '../common/FalconCardHeader'; +import Flex from '../common/Flex'; +import JKTooltip from '../common/JKTooltip'; +import { useTranslation } from 'react-i18next'; +import AsyncSelect from 'react-select/async'; +import { useAuth } from '../../context/UserAuth'; +import { getFriends } from '../../helpers/rest'; +import Avatar from '../common/Avatar'; -function JKNewMusicSession() { +const CustomOption = props => { + const { data, innerRef, innerProps } = props; return ( -
JK New Music Session
- ) -} +
+ +
+ +
+
{data.label}
+
+
+ ); +}; -export default JKNewMusicSession \ No newline at end of file +const JKNewMusicSession = () => { + const { t } = useTranslation(); + const { currentUser } = useAuth(); + + const friendOptions = async inputValue => { + let matches = []; + if (inputValue && inputValue.length >= 3) { + await getFriends(currentUser.id) + .then(resp => { + return resp.json(); + }) + .then(data => { + matches = data + .filter( + friend => + friend.first_name.toLowerCase().includes(inputValue.toLowerCase()) || + friend.last_name.toLowerCase().includes(inputValue.toLowerCase()) + ) + .map(opt => ({ + photoUrl: opt.photo_url, + label: `${opt.first_name} ${opt.last_name}`, + value: opt.id + })); + }); + } + return matches; + }; + + return ( +
+ + + +
+ + + + + + + + + + + + + (e.inputValue ? 'No options' : null)} + components={{ + Option: CustomOption, + DropdownIndicator: () => null, + IndicatorSeparator: () => null + }} + styles={{ + control: (baseStyles, state) => ({ + ...baseStyles, + borderRadius: '1.25em' + }) + }} + /> + + + + + + + + +
+
+
+
+ ); +}; + +export default JKNewMusicSession; diff --git a/jam-ui/src/helpers/rest.js b/jam-ui/src/helpers/rest.js index 4349df431..a185c1118 100644 --- a/jam-ui/src/helpers/rest.js +++ b/jam-ui/src/helpers/rest.js @@ -59,6 +59,14 @@ export const getInstruments = () => { // }) // } +export const getFriends = (userId) => { + return new Promise((resolve, reject) => { + apiFetch(`/users/${userId}/friends`) + .then(response => resolve(response)) + .catch(error => reject(error)) + }) +} + export const addFriend = (userId, friendId) => { return new Promise((resolve, reject) => { apiFetch(`/users/${userId}/friend_requests`, {