File size: 1,039 Bytes
b2360b8
 
 
e83084c
b2360b8
 
 
 
 
 
 
e83084c
b2360b8
 
 
 
 
 
 
 
 
 
 
 
 
e83084c
b2360b8
 
 
 
 
 
e83084c
b2360b8
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use client';

import { useEffect, useRef } from 'react';
import { useTheme } from '@/contexts/theme';

type Props = {
  pdbId: string;
  height?: string;
};

export default function StructureViewer({ pdbId, height = 'h-96' }: Props) {
  const { theme } = useTheme();
  const containerRef = useRef<HTMLDivElement>(null);
  const viewerId = `pdbe-${pdbId.toLowerCase()}`;

  useEffect(() => {
    const container = containerRef.current;
    if (!container) return;

    container.innerHTML = '';

    const el = document.createElement('pdbe-molstar');
    el.setAttribute('molecule-id', pdbId.toLowerCase());
    el.setAttribute('hide-controls', '');
    el.setAttribute('loading-overlay', '');
    el.setAttribute('background-color', theme === 'light' ? '#FFFFFF' : '#06060B');
    el.id = viewerId;
    container.appendChild(el);

    return () => {
      container.innerHTML = '';
    };
  }, [pdbId, viewerId, theme]);

  return (
    <div ref={containerRef} className={`w-full ${height} rounded-xl overflow-hidden border-0`} />
  );
}