Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add scrapper #2490

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/components/mindset/components/LandingPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useState } from 'react'
import { useEffect, useState } from 'react'
import { FieldValues } from 'react-hook-form'
import styled from 'styled-components'
import { Flex } from '~/components/common/Flex'
import { NODE_ADD_ERROR } from '~/constants'
import { api } from '~/network/api'
import { getSchemaAll } from '~/network/fetchSourcesData'
import { useDataStore } from '~/stores/useDataStore'
import { useMindsetStore } from '~/stores/useMindsetStore'
import { useSchemaStore } from '~/stores/useSchemaStore'
import { SubmitErrRes } from '~/types'
import { colors } from '~/utils/colors'
import { ChevronRight } from '../Icon/ChevronRight'
Expand Down Expand Up @@ -44,6 +46,21 @@ export const LandingPage = () => {
const [requestError, setRequestError] = useState<string>('')
const { setRunningProjectId } = useDataStore((s) => s)
const { setSelectedEpisodeId, setSelectedEpisodeLink } = useMindsetStore((s) => s)
const { setSchemas } = useSchemaStore((s) => s)

useEffect(() => {
const fetchSchemaData = async () => {
try {
const response = await getSchemaAll()

setSchemas(response.schemas.filter((schema) => !schema.is_deleted))
} catch (err) {
console.error('Error fetching schema:', err)
}
}

fetchSchemaData()
}, [setSchemas])

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { value } = e.target
Expand Down
25 changes: 10 additions & 15 deletions src/components/mindset/components/Marker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { memo } from 'react'
import styled from 'styled-components'
import { Flex } from '~/components/common/Flex'
import { Tooltip } from '~/components/common/ToolTip'
import { useSchemaStore } from '~/stores/useSchemaStore'
import { colors } from '~/utils/colors'

type Props = {
type: string
name: string
left: number
img: string
}
Expand All @@ -18,24 +16,22 @@ type BadgeProps = {
label: string
}

export const Marker = memo(({ type, name, left, img }: Props) => {
export const Marker = memo(({ type, left, img }: Props) => {
const [normalizedSchemasByType] = useSchemaStore((s) => [s.normalizedSchemasByType])

const primaryColor = normalizedSchemasByType[type]?.primary_color
const primaryIcon = normalizedSchemasByType[type]?.icon

const icon = primaryIcon ? `svg-icons/${primaryIcon}.svg` : 'thing_badge.svg'
const icon = primaryIcon ? `svg-icons/${primaryIcon}.svg` : ''

const badgeProps: Omit<BadgeProps, 'label'> = {
iconStart: img ?? icon,
iconStart: img || icon,
color: primaryColor ?? colors.THING,
}

return (
<MarkerWrapper style={{ left: `${left}%` }}>
<Tooltip content={`${name || type}`}>
<Badge {...badgeProps} label={type} />
</Tooltip>
<Badge {...badgeProps} label={type} />
</MarkerWrapper>
)
})
Expand All @@ -44,7 +40,7 @@ Marker.displayName = 'Marker'

const Badge = ({ iconStart, color, label }: BadgeProps) => (
<EpisodeWrapper color={color}>
<img alt={label} className="badge__img" src={iconStart} />
{iconStart && <img alt={label} className="badge__img" src={iconStart} />}
</EpisodeWrapper>
)

Expand All @@ -57,7 +53,6 @@ const EpisodeWrapper = styled(Flex).attrs({
overflow: hidden;
justify-content: center;
align-items: center;
padding: 0 4px;

.badge__img {
width: 10px;
Expand All @@ -68,12 +63,12 @@ const EpisodeWrapper = styled(Flex).attrs({

const MarkerWrapper = styled.div`
position: absolute;
top: -4px; /* Adjust as needed to center above the progress bar */
width: 8px;
height: 8px;
top: -6px;
width: 12px;
height: 12px;
border-radius: 4px;
background-color: ${colors.white};
border-radius: 50%;
transform: translateX(-50%); /* Center the marker horizontally */
transform: translateX(-50%);
transform: translateX(-50%) translateY(-50%);
top: 50%;
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,29 @@ type Props = {
handleProgressChange: (_: Event, value: number | number[]) => void
}

export const ProgressBar = ({ duration, markers, handleProgressChange, playingTIme }: Props) => (
<ProgressWrapper>
<ProgressSlider max={duration} onChange={handleProgressChange} value={playingTIme} />
{markers.map((node) => {
const position = ((node?.start || 0) / duration) * 100
const type = node?.node_type || ''
const name = node?.properties?.name || ''
const img = node?.properties?.image_url || ''
export const ProgressBar = ({ duration, markers, handleProgressChange, playingTIme }: Props) => {
const thumbWidth = (10 / duration) * 100

return <Marker key={node.ref_id} img={img} left={position} name={name} type={type} />
})}
</ProgressWrapper>
)
return (
<ProgressWrapper>
<ProgressSlider max={duration} onChange={handleProgressChange} thumbWidth={thumbWidth} value={playingTIme} />
{markers.map((node) => {
const position = ((node?.start || 0) / duration) * 100
const type = node?.node_type || ''
const img = node?.properties?.image_url || ''

return <Marker key={node.ref_id} img={img} left={position} type={type} />
})}
</ProgressWrapper>
)
}

const ProgressWrapper = styled(Flex)`
position: relative;
flex: 1 1 100%;
`

const ProgressSlider = styled(Slider)`
const ProgressSlider = styled(Slider)<{ thumbWidth: number }>`
&& {
z-index: 20;
color: ${colors.white};
Expand All @@ -42,9 +45,11 @@ const ProgressSlider = styled(Slider)`
border: none;
}
.MuiSlider-thumb {
width: 10px;
height: 10px;
background-color: ${colors.white};
width: ${({ thumbWidth }) => `${thumbWidth}%`};
height: 54px;
border-radius: 8px;
background-color: ${colors.primaryBlue};
opacity: 0.2;
&:before {
box-shadow: '0 4px 8px rgba(0,0,0,0.4)';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useState } from 'react'
import styled from 'styled-components'
import { usePlayerStore } from '~/stores/usePlayerStore'
import { colors } from '~/utils'
import { secondsToMediaTime } from '~/utils/secondsToMediaTime'

type Props = {
transcriptString: string
Expand Down Expand Up @@ -51,11 +52,11 @@ export const Viewer = ({ transcriptString }: Props) => {
return (
<Wrapper>
{transcriptData.map((i) => {
const start = i.start.toFixed(2)
const end = i.end.toFixed(2)
const start = secondsToMediaTime(i.start)
const end = secondsToMediaTime(i.end)

return (
<Paragraph key={i.id}>
<Paragraph key={i.start}>
<Start>
{start}:{end}
</Start>
Expand All @@ -82,6 +83,9 @@ const Paragraph = styled.div`

const Wrapper = styled.div`
width: 100%;
height: 100%;
overflow: scroll;
padding-right: 4px;
`

const Start = styled.span``
Expand Down
30 changes: 0 additions & 30 deletions src/network/askQuestion/index.ts

This file was deleted.

27 changes: 1 addition & 26 deletions src/network/fetchGraphData/const.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
import { GraphStyle } from '~/stores/useDataStore'
import { generateEarthGraphPositions } from '~/transformers/earthGraph'
import { generateForceGraphPositions } from '~/transformers/forceGraph'
import { generateSphereGraphPositions } from '~/transformers/sphereGraph'
import { generateSplitGraphPositions } from '~/transformers/splitGraph'
import { GraphData, Link, NodeExtended } from '~/types'

export const shouldIncludeTopics = true
export const maxScale = 26
import { GraphData } from '~/types'

export const defaultData: GraphData = {
links: [],
nodes: [],
}

export const getGraphDataPositions = (graphStyle: GraphStyle, nodes: NodeExtended[], links: Link[]) => {
// give nodes and links positions based on graphStyle
if (graphStyle === 'split') {
return generateSplitGraphPositions(nodes, links)
}

if (graphStyle === 'sphere') {
return generateSphereGraphPositions(nodes)
}

if (graphStyle === 'earth') {
return generateEarthGraphPositions(nodes)
}

return generateForceGraphPositions(nodes, links)
}
48 changes: 0 additions & 48 deletions src/network/teach/index.ts

This file was deleted.

Loading