-
-
-
{
- // eslint-disable-next-line no-console
- console.log(data);
- }}
- />
+
+
+
+
+
{
+ // eslint-disable-next-line no-console
+ console.log(value);
+ }}
/>
-
+ {Array.from({ length: 10 }).map((_, index) => (
+
+ ))}
-
+
);
diff --git a/apps/portal/src/utils/questions/constants.ts b/apps/portal/src/utils/questions/constants.ts
new file mode 100644
index 00000000..966e1a1f
--- /dev/null
+++ b/apps/portal/src/utils/questions/constants.ts
@@ -0,0 +1,108 @@
+import type { FilterChoices } from '~/components/questions/filter/FilterSection';
+
+export const COMPANIES: FilterChoices = [
+ {
+ label: 'Google',
+ value: 'google',
+ },
+ {
+ label: 'Meta',
+ value: 'meta',
+ },
+];
+
+// Code, design, behavioral
+export const QUESTION_TYPES: FilterChoices = [
+ {
+ label: 'Coding',
+ value: 'coding',
+ },
+ {
+ label: 'Design',
+ value: 'design',
+ },
+ {
+ label: 'Behavioral',
+ value: 'behavioral',
+ },
+];
+
+export const QUESTION_AGES: FilterChoices = [
+ {
+ label: 'Last month',
+ value: 'last-month',
+ },
+ {
+ label: 'Last 6 months',
+ value: 'last-6-months',
+ },
+ {
+ label: 'Last year',
+ value: 'last-year',
+ },
+ {
+ label: 'All',
+ value: 'all',
+ },
+];
+
+export const LOCATIONS: FilterChoices = [
+ {
+ label: 'Singapore',
+ value: 'singapore',
+ },
+ {
+ label: 'Menlo Park',
+ value: 'menlopark',
+ },
+ {
+ label: 'California',
+ value: 'california',
+ },
+ {
+ label: 'Hong Kong',
+ value: 'hongkong',
+ },
+ {
+ label: 'Taiwan',
+ value: 'taiwan',
+ },
+];
+
+export const SAMPLE_QUESTION = {
+ answerCount: 10,
+ commentCount: 10,
+ company: 'Google',
+ content:
+ 'Given an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums andiven an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums andiven an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums andiven an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums andiven an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums andiven an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums andiven an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums andiven an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums and',
+ location: 'Menlo Park, CA',
+ receivedCount: 12,
+ role: 'Software Engineer',
+ timestamp: 'Last month',
+ upvoteCount: 5,
+};
+
+export const SAMPLE_ANSWER = {
+ authorImageUrl: 'https://avatars.githubusercontent.com/u/66356390?v=4',
+ authorName: 'Jeff Sieu',
+ commentCount: 10,
+ content: 'This is a sample answer',
+ createdAt: new Date(2014, 8, 1, 11, 30, 40),
+ upvoteCount: 10,
+};
+
+export const SAMPLE_QUESTION_COMMENT = {
+ authorImageUrl: 'https://avatars.githubusercontent.com/u/66356390?v=4',
+ authorName: 'Jeff Sieu',
+ content: 'This is a sample question comment',
+ createdAt: new Date(2014, 8, 1, 11, 30, 40),
+ upvoteCount: 10,
+};
+
+export const SAMPLE_ANSWER_COMMENT = {
+ authorImageUrl: 'https://avatars.githubusercontent.com/u/66356390?v=4',
+ authorName: 'Jeff Sieu',
+ content: 'This is an sample answer comment',
+ createdAt: new Date(2014, 8, 1, 11, 30, 40),
+ upvoteCount: 10,
+};
diff --git a/apps/portal/src/utils/questions/useFormRegister.ts b/apps/portal/src/utils/questions/useFormRegister.ts
new file mode 100644
index 00000000..42ab2fc5
--- /dev/null
+++ b/apps/portal/src/utils/questions/useFormRegister.ts
@@ -0,0 +1,43 @@
+import type { ChangeEvent } from 'react';
+import { useCallback } from 'react';
+import type { FieldValues, UseFormRegister } from 'react-hook-form';
+
+export const useFormRegister =
(
+ register: UseFormRegister,
+) => {
+ const formRegister = useCallback(
+ (...args: Parameters) => {
+ const { onChange, ...rest } = register(...args);
+ return {
+ ...rest,
+ onChange: (value: string, event: ChangeEvent) => {
+ onChange(event);
+ },
+ };
+ },
+ [register],
+ );
+ return formRegister;
+};
+
+export const useSelectRegister = (
+ register: UseFormRegister,
+) => {
+ const formRegister = useCallback(
+ (...args: Parameters) => {
+ const { onChange, ...rest } = register(...args);
+ return {
+ ...rest,
+ onChange: (value: string) => {
+ onChange({
+ target: {
+ value,
+ },
+ });
+ },
+ };
+ },
+ [register],
+ );
+ return formRegister;
+};
diff --git a/apps/portal/src/utils/questions/useSearchFilter.ts b/apps/portal/src/utils/questions/useSearchFilter.ts
new file mode 100644
index 00000000..711f5ead
--- /dev/null
+++ b/apps/portal/src/utils/questions/useSearchFilter.ts
@@ -0,0 +1,69 @@
+import { useRouter } from 'next/router';
+import { useCallback, useEffect, useState } from 'react';
+
+export const useSearchFilter = (
+ name: string,
+ defaultValues?: Array,
+) => {
+ const [isInitialized, setIsInitialized] = useState(false);
+ const router = useRouter();
+
+ const [filters, setFilters] = useState>(defaultValues || []);
+
+ useEffect(() => {
+ if (router.isReady && !isInitialized) {
+ // Initialize from query params
+ const query = router.query[name];
+ if (query) {
+ const queryValues = Array.isArray(query) ? query : [query];
+ setFilters(queryValues);
+ } else {
+ // Try to load from local storage
+ const localStorageValue = localStorage.getItem(name);
+ if (localStorageValue !== null) {
+ const loadedFilters = JSON.parse(localStorageValue);
+ setFilters(loadedFilters);
+ router.replace({
+ pathname: router.pathname,
+ query: {
+ ...router.query,
+ [name]: loadedFilters,
+ },
+ });
+ }
+ }
+ setIsInitialized(true);
+ }
+ }, [isInitialized, name, router]);
+
+ const setFiltersCallback = useCallback(
+ (newFilters: Array) => {
+ setFilters(newFilters);
+ localStorage.setItem(name, JSON.stringify(newFilters));
+ router.replace({
+ pathname: router.pathname,
+ query: {
+ ...router.query,
+ [name]: newFilters,
+ },
+ });
+ },
+ [name, router],
+ );
+
+ return [filters, setFiltersCallback, isInitialized] as const;
+};
+
+export const useSearchFilterSingle = (name: string, defaultValue: string) => {
+ const [filters, setFilters, isInitialized] = useSearchFilter(name, [
+ defaultValue,
+ ]);
+
+ return [
+ filters[0],
+ (value: string) => {
+ setFilters([value]);
+ },
+ isInitialized,
+ ] as const;
+};
diff --git a/apps/portal/src/utils/questions/withHref.tsx b/apps/portal/src/utils/questions/withHref.tsx
new file mode 100644
index 00000000..681f7122
--- /dev/null
+++ b/apps/portal/src/utils/questions/withHref.tsx
@@ -0,0 +1,21 @@
+const withHref = >(
+ Component: React.ComponentType,
+) => {
+ return (
+ props: Props & {
+ href: string;
+ },
+ ) => {
+ const { href, ...others } = props;
+
+ return (
+
+
+
+ );
+ };
+};
+
+export default withHref;