Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimNed committed Jan 10, 2024
1 parent f9e9137 commit 54e4ae9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 101 deletions.
16 changes: 8 additions & 8 deletions src/activity-types/anthem.constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SampleType } from './anthem.types';
import { TrackType } from './anthem.types';
import type { AnthemData } from './anthem.types';

export const DEFAULT_ANTHEM_DATA: AnthemData = {
Expand All @@ -8,55 +8,55 @@ export const DEFAULT_ANTHEM_DATA: AnthemData = {
startTime: 0,
duration: 0,
volume: 1,
type: SampleType.VOCALS,
type: TrackType.VOCALS,
label: 'Piste vocale La La',
},
{
sampleUrl: '',
startTime: 0,
duration: 0,
volume: 1,
type: SampleType.HARMONIC1,
type: TrackType.HARMONIC1,
label: 'Piste harmonique 1',
},
{
sampleUrl: '',
startTime: 0,
duration: 0,
volume: 1,
type: SampleType.HARMONIC2,
type: TrackType.HARMONIC2,
label: 'Piste harmonique 2',
},
{
sampleUrl: '',
startTime: 0,
duration: 0,
volume: 1,
type: SampleType.MELODIC1,
type: TrackType.MELODIC1,
label: 'Piste mélodique 1',
},
{
sampleUrl: '',
startTime: 0,
duration: 0,
volume: 1,
type: SampleType.MELODIC2,
type: TrackType.MELODIC2,
label: 'Piste mélodique 2',
},
{
sampleUrl: '',
startTime: 0,
duration: 0,
volume: 1,
type: SampleType.RYTHMIC1,
type: TrackType.RYTHMIC1,
label: 'Piste rythmique 1',
},
{
sampleUrl: '',
startTime: 0,
duration: 0,
volume: 1,
type: SampleType.RYTHMIC2,
type: TrackType.RYTHMIC2,
label: 'Piste rythmique 2',
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/activity-types/anthem.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export type Track = {
startTime: number;
duration: number;
volume: number;
type: SampleType;
type: TrackType;
label: string;
};

export enum SampleType {
export enum TrackType {
VOCALS = 0,
HARMONIC1 = 1,
HARMONIC2 = 2,
Expand Down
4 changes: 2 additions & 2 deletions src/components/audio/AnthemTrack/AnthemTrack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import styles from './AnthemTrack.module.css';
import type { Track } from 'src/activity-types/anthem.types';
import { AnthemSampleEditor } from 'src/components/activities/content/editors/AnthemSampleEditor/AnthemSampleEditor';

interface SampleTrackProps {
interface AnthemTrackProps {
id: number;
track: Track;
updateTrackInActivity: (id: number, track: Track) => void;
}

const AnthemTrack = ({ id, track, updateTrackInActivity }: SampleTrackProps) => {
const AnthemTrack = ({ id, track, updateTrackInActivity }: AnthemTrackProps) => {
const [isEditingLabel, setIsEditingLabel] = React.useState(false);
const [isAnthemSampleEditorModalOpen, setIsAnthemSampleEditorModalOpen] = React.useState(false);

Expand Down
4 changes: 4 additions & 0 deletions src/contexts/activityContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ export const ActivityContextProvider = ({ children }: React.PropsWithChildren<Re

const createActivityIfNotExist = React.useCallback(
async (type: number, selectedPhase: number, subType?: number, initialData?: AnyData, isVillageActivity?: boolean) => {
console.log('CREATE ACTIVITY');

Check failure on line 175 in src/contexts/activityContext.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
if (user === null || village === null) {
console.log('NO USER OR VILLAGE');

Check failure on line 177 in src/contexts/activityContext.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
return;
}

Expand All @@ -192,7 +194,9 @@ export const ActivityContextProvider = ({ children }: React.PropsWithChildren<Re
];
if (response.length > 0) {
setActivity(response[0]);
console.log('RESPONSE LENGTH > 0');

Check failure on line 197 in src/contexts/activityContext.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
} else {
console.log('RESPONSE LENGTH < 0, CREATE NEW ACTIVITY');

Check failure on line 199 in src/contexts/activityContext.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
createNewActivity(type, selectedPhase, subType, initialData);
}
},
Expand Down
101 changes: 12 additions & 89 deletions src/pages/parametrer-hymne/1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { isAnthem } from 'src/activity-types/anyActivity';
import { Base } from 'src/components/Base';
import { Steps } from 'src/components/Steps';
import { StepsButton } from 'src/components/StepsButtons';
import { AnthemSampleEditor } from 'src/components/activities/content/editors/AnthemSampleEditor/AnthemSampleEditor';
import AnthemTrack from 'src/components/audio/AnthemTrack/AnthemTrack';
import { ActivityContext } from 'src/contexts/activityContext';
import { VillageContext } from 'src/contexts/villageContext';
Expand All @@ -28,10 +27,8 @@ const AnthemStep1 = () => {
const data = (activity?.data as AnthemData) || null;

const [isLoading, setIsLoading] = React.useState(false);
const [isAnthemEditorModalOpen, setIsAnthemEditorModalOpen] = React.useState(false);

const [times, setTimes] = React.useState<Record<number, number>>({});
const [editingSampleIndex, setEditingSampleIndex] = React.useState<number | null>(null);

const created = React.useRef(false);
React.useEffect(() => {
Expand All @@ -44,6 +41,11 @@ const AnthemStep1 = () => {
createActivityIfNotExist(ActivityType.ANTHEM, selectedPhase, undefined, DEFAULT_ANTHEM_DATA, true);
}
}
// if (created.current) return;
// if ((!('activity-id' in router.query) && !('edit' in router.query)) || (activity && !isAnthem(activity))) {
// created.current = true;
// createActivityIfNotExist(ActivityType.ANTHEM, selectedPhase, undefined, DEFAULT_ANTHEM_DATA, true);
// }
}, [activity, createActivityIfNotExist, router, selectedPhase]);

const onNext = async () => {
Expand All @@ -57,11 +59,6 @@ const AnthemStep1 = () => {
router.push('/parametrer-hymne/2');
};

const handleAddSample = (id: number) => {
setEditingSampleIndex(id);
setIsAnthemEditorModalOpen(true);
};

const updateTrackInActivity = (id: number, sample: Track) => {
const tracks = [...data.tracks];
tracks[id] = { ...tracks[id], label: sample.label };
Expand All @@ -80,91 +77,17 @@ const AnthemStep1 = () => {
activeStep={0}
urls={['/parametrer-hymne/1', '/parametrer-hymne/2', '/parametrer-hymne/3', '/parametrer-hymne/4', '/parametrer-hymne/5']}
/>
{/* <p style={{ margin: '25px 0 25px' }}>La piste vocal du couplet, La La.</p>
{data &&
(data.verseAudios || []).map((audio, idx) => (
<React.Fragment key={idx}>
{idx === 1 && <div style={{ margin: '25px 0 25px' }}>Les différentes pistes sonores du couplet (utiles au mixage)</div>}
<div style={{ display: 'flex', alignItems: 'center', marginBottom: '10px' }}>
{React.createElement(musicIcons[idx], { key: `descimg--${idx}` })}
<div style={{ width: '200px', marginLeft: '10px' }}>
{editingIndex === idx ? (
<input
type="text"
value={audio.label}
onBlur={() => {
if (audio.label.trim() !== '') {
setEditingIndex(null);
}
}}
onChange={(e) => {
data.verseAudios[idx].label = e.target.value;
updateActivity({ data: { ...data } });
}}
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault();
if (audio.label.trim() !== '') {
setEditingIndex(null);
}
}
}}
autoFocus
/>
) : (
<span onClick={() => setEditingIndex(idx)}>{audio.label}</span>
)}
</div>
<div>
{data.verseAudios[idx].display && (
<AnthemEditor
key={`anthem-edit--${idx}`}
value={audio.value}
onChange={onUpdateVerseAudios(idx)}
onDelete={() => {
onUpdateVerseAudios(idx)('');
}}
setTime={(time) => {
setTimes({ ...times, [idx]: time });
}}
idx={idx}
edit
/>
)}
{!audio.value && (
<Button
onClick={() => {
data.verseAudios[idx].display = true;
updateActivity({ data: { ...data } });
}}
variant="text"
className="navigation__button full-width"
style={{
justifyContent: 'flex-start',
width: 'auto',
boxShadow: '0px 4px 7px rgba(0, 0, 0, 0.1)',
color: 'black',
fontWeight: 'bold',
}}
endIcon={<SoundIcon />}
>
Ajouter un son
</Button>
)}
</div>
</div>
</React.Fragment>
))}
</div> */}
<div className={styles.trackSelectionContainer}>
<h1>Mettre en ligne les pistes sonores du couplet</h1>
<p> Commencez le paramétrage en mettant en ligne les différentes pistes sonores du couplet : </p>
<p className={styles.trackSelectionTitle}>La piste vocal du couplet, La La.</p>
<AnthemTrack id={0} track={data.tracks[0]} updateTrackInActivity={updateTrackInActivity} />
<div className={styles.trackSelectionTitle}>Les différentes pistes sonores du couplet (utiles au mixage)</div>
{(data.tracks || []).map((track, id) => {
return <AnthemTrack key={id} id={id} track={track} updateTrackInActivity={updateTrackInActivity} />;
})}
{data &&
(data.tracks || []).map((track, id) => {
{
id === 1 && <div className={styles.trackSelectionTitle}>Les différentes pistes sonores du couplet (utiles au mixage)</div>;
}
<AnthemTrack key={id} id={id} track={track} updateTrackInActivity={updateTrackInActivity} />;
})}
</div>
</div>
<StepsButton next={onNext} />
Expand Down

0 comments on commit 54e4ae9

Please sign in to comment.