Skip to content

Commit

Permalink
Merge pull request #15 from theHandsomestNerd/sanity-schema-change
Browse files Browse the repository at this point in the history
control over which documents can be searched by a page.
  • Loading branch information
tmanundercover committed Dec 13, 2023
2 parents fedc9ad + 6db5e1d commit 87cbbed
Show file tree
Hide file tree
Showing 22 changed files with 192 additions and 47 deletions.
1 change: 1 addition & 0 deletions functions/src/groqQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const SERVICE =


const HOMEPAGE = `_type,
_id,
title,
isUnderConstruction,
releaseDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export default {
title: 'Title of Section',
type: 'string',
},
{
name: 'searchableOnPages',
title: 'Make Searchable on pages',
type: 'array',
of:[{type: "reference", to: {type:"homePage"}}]
},
{
name: 'introduction',
title: 'Introduction',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ export default {
title: 'Form Submit Button Text',
type: 'string'
},
{
name: 'searchableOnPages',
title: 'Make Searchable on pages',
type: 'array',
of:[{type: "reference", to: {type:"homePage"}}]
},

],
preview: {
select: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export default {
title: 'Job Description or Requirements',
type: 'text',
},
{
name: 'searchableOnPages',
title: 'Make Searchable on pages',
type: 'array',
of:[{type: "reference", to: {type:"homePage"}}]
},

],
preview: {
select: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,12 @@ export default {
}
]
},
{
name: 'searchableOnPages',
title: 'Make Searchable on pages',
type: 'array',
of:[{type: "reference", to: {type:"homePage"}}]
},

]
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export default {
to: [{type: "ResumeSkill"}]
}]
},
{
name: 'searchableOnPages',
title: 'Make Searchable on pages',
type: 'array',
of:[{type: "reference", to: {type:"homePage"}}]
},

],
preview: {
select: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,12 @@ export default {
type: 'reference',
to:[{type: 'MuiTheme'}]
},
{
name: 'searchableOnPages',
title: 'Make Searchable on pages',
type: 'array',
of:[{type: "reference", to: {type:"homePage"}}]
},

]
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export default {
hotspot: true,
},
},
{
name: 'searchableOnPages',
title: 'Make Searchable on pages',
type: 'array',
of:[{type: "reference", to: {type:"homePage"}}]
},

],
preview: {
select: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,12 @@ export default {
}
]
},
{
name: 'searchableOnPages',
title: 'Make Searchable on pages',
type: 'array',
of:[{type: "reference", to: {type:"homePage"}}]
},

]
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,12 @@ export default {
type: 'array',
of:[{type: 'image'}]
},
{
name: 'searchableOnPages',
title: 'Make Searchable on pages',
type: 'array',
of:[{type: "reference", to: {type:"homePage"}}]
},

]
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,12 @@ export default {
}
]
},
{
name: 'searchableOnPages',
title: 'Make Searchable on pages',
type: 'array',
of:[{type: "reference", to: {type:"homePage"}}]
},

]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export default {
name: 'title',
title: 'Title of Skillset',
type: 'string',
}
},
{
name: 'searchableOnPages',
title: 'Make Searchable on pages',
type: 'array',
of:[{type: "reference", to: {type:"homePage"}}]
},

]
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,12 @@ export default {
to: [{type: "ResumeSkill"}]
}]
},
{
name: 'searchableOnPages',
title: 'Make Searchable on pages',
type: 'array',
of:[{type: "reference", to: {type:"homePage"}}]
},

]
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ export default {
of: [{type: "reference", to:{type:"ResumeSkillset"}},
]
},
{
name: 'searchableOnPages',
title: 'Make Searchable on pages',
type: 'array',
of:[{type: "reference", to: {type:"homePage"}}]
},
]
}
2 changes: 1 addition & 1 deletion src/common/sanityIo/Types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {SanityImageSource} from "@sanity/asset-utils";
import {SanityImageAsset, ThwServiceItemNoRefType} from "../../components/BlockContentTypes";
import {Slug} from "@sanity/types";
import BusinessContact from "../../../sanityIo/schemas/businessContact";

export type SanitySlug = Slug

Expand Down Expand Up @@ -53,6 +52,7 @@ export type SanityBusinessContact = {
export type SanityTransformHwHomePage = {
_type?: string
title?: string
_id?:string
description?: string
bookAppointmentLink?: string
bookAppointmentQrCode?: SanityImageSource
Expand Down
3 changes: 2 additions & 1 deletion src/common/sanityIo/groqQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const SERVICE =
`


const HOMEPAGE = `_type,
const HOMEPAGE = `_type,
_id,
title,
isUnderConstruction,
releaseDate,
Expand Down
27 changes: 20 additions & 7 deletions src/components/block-content-ui/cmsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,9 @@ const useFetchServicesQuery = (pageSlug?: string) => {
});
}

const fullTextSearch = (textToSearch: string): Promise<any> => {
const fullTextSearch = (textToSearch: string, pageId: string): Promise<any> => {

console.log("the page id", pageId)
return sanityClient
.fetch(
`*[
Expand All @@ -476,6 +477,7 @@ const fullTextSearch = (textToSearch: string): Promise<any> => {
careerTitle,
introduction,
name,
email,
contentText,
contentTexts,
contentTitle,
Expand All @@ -486,18 +488,17 @@ const fullTextSearch = (textToSearch: string): Promise<any> => {
contentSummaryTitle,
contentSummaryTexts,
videoUrl,
] match '*${textToSearch}*']{
] match '*${textToSearch}*' && references('${pageId}')]{
...,
"skillsUsed" : skillsUsed[]->,
"skills" : skills[]->,
}`,
// {searchText: textToSearch}
).then((data: any) => {
console.log("data from fulltext search", data)
return data
})
}
const skillReferenceSearch = (skill: ResumeSkill): Promise<any> => {
const skillReferenceSearch = (skill: ResumeSkill, pageId: string): Promise<any> => {
return sanityClient
.fetch(
`*[references($searchText)]{
Expand All @@ -506,9 +507,21 @@ const skillReferenceSearch = (skill: ResumeSkill): Promise<any> => {
"skillsUsed" : skillsUsed[]->,
"skills":skills[]->,
}`,
{searchText: skill._id}
).then((data: any) => {
console.log("data from skillReference search", data)
{searchText: skill._id, pageId: pageId}
).then((data: any[]) => {


data.sort((left, right)=>{
if (left._type === right._type) {
return 0
}

if(left._type > right._type)
return 1

return -1
})

return data
})
}
Expand Down
28 changes: 21 additions & 7 deletions src/components/templates/mackenzies-mind/header/FullTextSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import makeStyles from "@mui/styles/makeStyles";
import {Theme} from "@mui/material/styles";
import {
AnimatedAboutUsSectionType,
HeroAnimatedContentSectionType,
HeroAnimatedContentSectionType, ResumeBioSectionType,
ResumeExperience,
ResumeSkill,
SanityHeroContentSlide,
Expand All @@ -18,6 +18,8 @@ import {
import ResumeExperienceItem from "../../my-digital-resume/resume-experience-section/ResumeExperienceItem";
import {COLORS} from "../../../../theme/common/ColorPalette";
import ResumeSkillReferences from "../../my-digital-resume/resume-skills-section/ResumeSkillReferences";
import PageContext from "../../../page-context/PageContext";
import ResumeBioSection from "../../my-digital-resume/resume-bio-section/ResumeBioSection";

export const useStyles = makeStyles((theme: Theme) => ({
endAdornedInput: {
Expand Down Expand Up @@ -55,10 +57,11 @@ const FullTextSearch: FunctionComponent<IProps> = (props: IProps) => {
const [searchText, setSearchText] = React.useState<string>()
const myClasses = useStyles(customizedTheme)
const [results, setResults] = React.useState<any[]>()
const pageContext = useContext(PageContext)
const searchCMS = async () => {
console.log("about to search full text")
if (searchText) {
const cmsResponse = await cmsClient.fullTextSearch(searchText)
const cmsResponse = await cmsClient.fullTextSearch(searchText, pageContext.page?._id??"")
console.log("results", cmsResponse)
setResults(cmsResponse)
}
Expand Down Expand Up @@ -149,7 +152,6 @@ const FullTextSearch: FunctionComponent<IProps> = (props: IProps) => {
case "AnimatedServicesSection":
const convertedAnimatedServicesSection: AnimatedAboutUsSectionType = theResult;

console.log(convertedAnimatedServicesSection)
return <Grid container sx={{marginBottom: "16px"}}>
<Grid container item><Typography color='textSecondary'>Services:</Typography></Grid>
<Grid item sx={{paddingLeft: "16px"}} container>
Expand Down Expand Up @@ -181,25 +183,37 @@ const FullTextSearch: FunctionComponent<IProps> = (props: IProps) => {
padding: "16px"
}}>
<Grid container>
<Typography variant='h6' gutterBottom color='primary'>My Experience</Typography>
<Typography variant='h6' gutterBottom color='primary'>{convertedResumeExperience.title} Experience</Typography>
</Grid>
<ResumeExperienceItem experience={convertedResumeExperience}/>
</Grid>
case "ResumeSkill":
const convertedResumeSkill: ResumeSkill = theResult;

console.log(convertedResumeSkill)
return <Grid container sx={{
marginBottom: "16px",
backgroundColor: COLORS.LIGHTGRAY,
padding: "16px"
}}>
<Grid container>
<Typography variant='h6' gutterBottom color='primary'>My Skill
- {convertedResumeSkill.title}</Typography>
<Typography variant='h6' gutterBottom color='primary'>Experience with {convertedResumeSkill.title}</Typography>
</Grid>
<ResumeSkillReferences skill={convertedResumeSkill}/>
</Grid>
case "ResumeBioSection":
const resumeBioSectionObj: ResumeBioSectionType = theResult;

return <Grid container sx={{
marginBottom: "16px",
backgroundColor: COLORS.LIGHTGRAY,
padding: "16px"
}}>
<Grid container>
<Typography variant='h6' gutterBottom color='primary'>My Bio
- {resumeBioSectionObj.title}</Typography>
</Grid>
<ResumeBioSection sectionData={resumeBioSectionObj} homePage={pageContext.page}/>
</Grid>
default:
return <Grid container sx={{marginBottom: "16px"}}><Typography
color='textSecondary'>{theResult?._type}</Typography></Grid>
Expand Down
Loading

0 comments on commit 87cbbed

Please sign in to comment.