Skip to content

Commit

Permalink
fix(add-content): add github new source type
Browse files Browse the repository at this point in the history
  • Loading branch information
MirzaHanan committed Sep 19, 2024
1 parent 7ffb3a9 commit e052889
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions public/github_default.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/components/AddContentModal/SourceTypeStep/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FC } from 'react'
import styled from 'styled-components'
import { Flex } from '~/components/common/Flex'
import { Text } from '~/components/common/Text'
import { RSS, TWITTER_HANDLE, YOUTUBE_CHANNEL } from '~/constants'
import { GITHUB_REPOSITORY, RSS, TWITTER_HANDLE, YOUTUBE_CHANNEL } from '~/constants'
import { colors } from '~/utils'
import { extractNameFromLink } from '../utils'

Expand All @@ -27,6 +27,10 @@ const CONTENT_TYPE_MAPPING: Record<string, { [k: string]: string }> = {
label: 'RSS Feed',
img: 'rss_feed.svg',
},
[GITHUB_REPOSITORY]: {
label: 'GitHub Repository',
img: 'github_default.svg',
},
}

export const SourceTypeStep: FC<Props> = ({ onNextStep, onPrevStep, type, value }) => (
Expand Down
5 changes: 3 additions & 2 deletions src/components/AddContentModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import * as sphinx from 'sphinx-bridge'
import { BaseModal } from '~/components/Modal'
import {
DOCUMENT,
GITHUB_REPOSITORY,
isE2E,
LINK,
NODE_ADD_ERROR,
RSS,
TWITTER_HANDLE,
TWITTER_SOURCE,
WEB_PAGE,
YOUTUBE_CHANNEL,
isE2E,
} from '~/constants'
import { api } from '~/network/api'
import { useModal } from '~/stores/useModalStore'
Expand Down Expand Up @@ -80,7 +81,7 @@ const handleSubmitForm = async (
} else {
return
}
} else if (sourceType === YOUTUBE_CHANNEL || sourceType === RSS) {
} else if (sourceType === YOUTUBE_CHANNEL || sourceType === RSS || sourceType === GITHUB_REPOSITORY) {
body.source = data.source
body.source_type = sourceType
}
Expand Down
19 changes: 17 additions & 2 deletions src/components/AddContentModal/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { DOCUMENT, LINK, RSS, TWITTER_HANDLE, TWITTER_SOURCE, WEB_PAGE, YOUTUBE_CHANNEL } from '~/constants'
import {
DOCUMENT,
GITHUB_REPOSITORY,
LINK,
RSS,
TWITTER_HANDLE,
TWITTER_SOURCE,
WEB_PAGE,
YOUTUBE_CHANNEL,
} from '~/constants'

export const twitterHandlePattern = /\b(?:twitter\.com|x\.com)\/(?:@)?([\w_]+)(?:$|\?[^/]*$)/

Expand All @@ -14,6 +23,7 @@ const youtubeChannelPattern = /https?:\/\/(www\.)?youtube\.com\/(user\/)?(@)?([\

const genericUrlRegex = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/
const twitterBroadcastRegex = /https:\/\/twitter\.com\/i\/broadcasts\/([A-Za-z0-9_-]+)/
const githubRepoPattern = /https:\/\/github\.com\/[\w-]+\/[\w-]+/

export function getInputType(source: string) {
const linkPatterns = [
Expand Down Expand Up @@ -45,6 +55,10 @@ export function getInputType(source: string) {
return RSS
}

if (githubRepoPattern.test(source)) {
return GITHUB_REPOSITORY
}

if (genericUrlRegex.test(source)) {
return WEB_PAGE
}
Expand All @@ -60,4 +74,5 @@ export const extractNameFromLink = (inputString: string, type = ''): string | nu
return match ? match[1] : null
}

export const isSource = (type: string): boolean => !!type && [TWITTER_HANDLE, YOUTUBE_CHANNEL, RSS].includes(type)
export const isSource = (type: string): boolean =>
!!type && [TWITTER_HANDLE, YOUTUBE_CHANNEL, RSS, GITHUB_REPOSITORY].includes(type)

0 comments on commit e052889

Please sign in to comment.