-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Konstantin/rka 21 add job actions (#5)
* rka-21: move files around * rka-21: add job card actions * rka-21: clean up layout a bit * rka-21: add husky pre-commits and fix types
- Loading branch information
1 parent
63c7723
commit e648370
Showing
28 changed files
with
491 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bun typecheck |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/add/variant/renderer.tsx → app/add/components/variant/renderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Button } from '@radix-ui/themes' | ||
import type { BaseButtonProps } from '@radix-ui/themes/dist/esm/components/base-button.js' | ||
import type { ReactNode } from 'react' | ||
|
||
type ActionButtonProps = { | ||
loading: boolean | ||
clickHandler: () => void | ||
isActive: boolean | ||
colorActive: BaseButtonProps['color'] | ||
icon: ReactNode | ||
label: string | ||
} | ||
|
||
export const ActionButton = ({ | ||
loading, | ||
clickHandler, | ||
isActive, | ||
colorActive, | ||
icon, | ||
label, | ||
}: ActionButtonProps) => ( | ||
<Button | ||
loading={loading} | ||
onClick={clickHandler} | ||
size="1" | ||
color={isActive ? colorActive : 'gray'} | ||
variant="soft" | ||
> | ||
{icon} | ||
{label} | ||
</Button> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { SelectJob } from '@/lib/db/schema' | ||
import { logger } from '@/lib/logger' | ||
import type { ActionResponse } from '@/lib/types/api' | ||
|
||
export const createAction = | ||
<QR>(query: (jobId: SelectJob['id'], property: boolean) => Promise<QR>) => | ||
async ( | ||
jobId: SelectJob['id'], | ||
property: boolean, | ||
): Promise<ActionResponse<QR>> => { | ||
const l = logger.child({ jobId, property }) | ||
|
||
try { | ||
const result = await query(jobId, property) | ||
|
||
return { | ||
data: result, | ||
error: false, | ||
} | ||
} catch (error) { | ||
l.error(error) | ||
|
||
return { | ||
error: true, | ||
errorMessage: | ||
error instanceof Error | ||
? error.message | ||
: '[createAction] Unknown error', | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use server' | ||
import { | ||
queryMarkHidden, | ||
queryMarkSeen, | ||
queryMarkTopChoice, | ||
} from '@/lib/db/queries/job-action' | ||
import { createAction } from './create-action' | ||
|
||
export const actionMarkTopChoice = createAction(queryMarkTopChoice) | ||
export const actionMarkHidden = createAction(queryMarkHidden) | ||
export const actionMarkSeen = createAction(queryMarkSeen) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { SelectJob } from '@/lib/db/schema' | ||
import { useState } from 'react' | ||
import type { createAction } from '../actions/create-action' | ||
|
||
export const useJobAction = ( | ||
initialState: boolean, | ||
action: ReturnType<typeof createAction>, | ||
) => { | ||
const [isActive, setIsActive] = useState(initialState) | ||
const [loading, setLoading] = useState(false) | ||
|
||
const clickHandler = async (jobId: SelectJob['id']) => { | ||
const newState = !isActive | ||
|
||
setLoading(true) | ||
|
||
try { | ||
const result = await action(jobId, newState) | ||
|
||
if (result.error) { | ||
// TODO: Add toast notifications | ||
console.error(result.errorMessage) | ||
} else { | ||
setIsActive(newState) | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
} finally { | ||
setLoading(false) | ||
} | ||
} | ||
|
||
return { isActive, loading, clickHandler } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use client' | ||
import type { SelectJob } from '@/lib/db/schema' | ||
import { | ||
EyeNoneIcon, | ||
EyeOpenIcon, | ||
LightningBoltIcon, | ||
} from '@radix-ui/react-icons' | ||
import { Text } from '@radix-ui/themes' | ||
import { ActionButton } from './action-button' | ||
import { | ||
actionMarkHidden, | ||
actionMarkSeen, | ||
actionMarkTopChoice, | ||
} from './actions/mark-property' | ||
import { useJobAction } from './hooks/use-job-action' | ||
|
||
export const JobCardActions = ({ job }: { job: SelectJob }) => { | ||
const hidden = useJobAction(job.isHidden, actionMarkHidden) | ||
const topChoice = useJobAction(job.isTopChoice, actionMarkTopChoice) | ||
const seen = useJobAction(job.isSeen, actionMarkSeen) | ||
|
||
return ( | ||
<> | ||
<Text size="2" color="gray"> | ||
Mark as: | ||
</Text> | ||
<ActionButton | ||
isActive={hidden.isActive} | ||
loading={hidden.loading} | ||
clickHandler={() => hidden.clickHandler(job.id)} | ||
colorActive="sky" | ||
icon={<EyeNoneIcon />} | ||
label="Hidden" | ||
/> | ||
<ActionButton | ||
isActive={topChoice.isActive} | ||
loading={topChoice.loading} | ||
clickHandler={() => topChoice.clickHandler(job.id)} | ||
colorActive="plum" | ||
icon={<LightningBoltIcon />} | ||
label="Top Choice" | ||
/> | ||
<ActionButton | ||
isActive={seen.isActive} | ||
loading={seen.loading} | ||
clickHandler={() => seen.clickHandler(job.id)} | ||
colorActive="grass" | ||
icon={<EyeOpenIcon />} | ||
label="Seen" | ||
/> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ALTER TABLE "jobs" ADD COLUMN "is_seen" boolean DEFAULT false NOT NULL;--> statement-breakpoint | ||
ALTER TABLE "jobs" ADD COLUMN "is_hidden" boolean DEFAULT false NOT NULL;--> statement-breakpoint | ||
ALTER TABLE "jobs" ADD COLUMN "is_top_choice" boolean DEFAULT false NOT NULL;--> statement-breakpoint | ||
ALTER TABLE "jobs" ADD COLUMN "is_applied" boolean DEFAULT false NOT NULL; |
Oops, something went wrong.