Skip to content

Commit

Permalink
kruto
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont committed Jun 10, 2024
1 parent dd933f8 commit 99595c2
Show file tree
Hide file tree
Showing 28 changed files with 628 additions and 560 deletions.
28 changes: 14 additions & 14 deletions apps/api-gql/internal/gql/resolvers/overlays.resolver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions apps/api-gql/internal/gql/resolvers/overlays.resolver.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ import (
"log/slog"

"github.com/google/uuid"
"github.com/samber/lo"
model "github.com/satont/twir/libs/gomodels"
"github.com/twirapp/twir/apps/api-gql/internal/gql/gqlmodel"
)

func chatOverlayDbToGql(entity *model.ChatOverlaySettings) *gqlmodel.ChatOverlay {
var animation *gqlmodel.ChatOverlayAnimation
if entity.Animation != nil {
animation = lo.ToPtr(gqlmodel.ChatOverlayAnimation(*entity.Animation))
}

return &gqlmodel.ChatOverlay{
ID: entity.ID.String(),
MessageHideTimeout: int(entity.MessageHideTimeout),
Expand All @@ -35,7 +29,7 @@ func chatOverlayDbToGql(entity *model.ChatOverlaySettings) *gqlmodel.ChatOverlay
FontWeight: int(entity.FontWeight),
FontStyle: entity.FontStyle,
PaddingContainer: int(entity.PaddingContainer),
Animation: animation,
Animation: gqlmodel.ChatOverlayAnimation(entity.Animation),
}
}

Expand Down Expand Up @@ -83,7 +77,8 @@ func (r *Resolver) getChatOverlaySettings(

func (r *mutationResolver) updateChatOverlay(
ctx context.Context,
opts gqlmodel.ChatOverlayUpdateOpts,
id string,
opts gqlmodel.ChatOverlayMutateOpts,
) (bool, error) {
dashboardId, err := r.sessions.GetSelectedDashboard(ctx)
if err != nil {
Expand All @@ -93,7 +88,7 @@ func (r *mutationResolver) updateChatOverlay(
entity := model.ChatOverlaySettings{}
if err := r.gorm.
WithContext(ctx).
Where("channel_id = ? AND id = ?", dashboardId, opts.ID).
Where("channel_id = ? AND id = ?", dashboardId, id).
First(&entity).Error; err != nil {
return false, fmt.Errorf("failed to get chat overlay settings: %w", err)
}
Expand Down Expand Up @@ -163,7 +158,7 @@ func (r *mutationResolver) updateChatOverlay(
}

if opts.Animation.IsSet() {
entity.Animation = lo.ToPtr(model.ChatOverlaySettingsAnimationType(*opts.Animation.Value()))
entity.Animation = model.ChatOverlaySettingsAnimationType(*opts.Animation.Value())
}

if err := r.gorm.
Expand Down
10 changes: 6 additions & 4 deletions apps/api-gql/schema/overlays.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ extend type Query {
}

extend type Mutation {
chatOverlayUpdate(opts: ChatOverlayUpdateOpts!): Boolean! @isAuthenticated @hasChannelRolesDashboardPermission(permission: MANAGE_OVERLAYS)
chatOverlayUpdate(id: String!, opts: ChatOverlayMutateOpts!): Boolean! @isAuthenticated @hasChannelRolesDashboardPermission(permission: MANAGE_OVERLAYS)
chatOverlayCreate(opts: ChatOverlayMutateOpts!): Boolean! @isAuthenticated @hasChannelRolesDashboardPermission(permission: MANAGE_OVERLAYS)
chatOverlayDelete(id: String!): Boolean! @isAuthenticated @hasChannelRolesDashboardPermission(permission: MANAGE_OVERLAYS)
}

extend type Subscription {
Expand All @@ -13,6 +15,7 @@ extend type Subscription {

enum ChatOverlayAnimation {
DISABLED
DEFAULT
}

type ChatOverlay {
Expand All @@ -33,11 +36,10 @@ type ChatOverlay {
fontWeight: Int!
fontStyle: String!
paddingContainer: Int!
animation: ChatOverlayAnimation
animation: ChatOverlayAnimation!
}

input ChatOverlayUpdateOpts {
id: String!
input ChatOverlayMutateOpts {
messageHideTimeout: Int
messageShowDelay: Int
preset: String
Expand Down
11 changes: 6 additions & 5 deletions frontend/dashboard/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { join, resolve } from 'path';
import { join, resolve } from 'node:path'
import process from 'node:process'

import type { CodegenConfig } from '@graphql-codegen/cli';
import type { CodegenConfig } from '@graphql-codegen/cli'

const schemaDir = resolve(join(process.cwd(), '..', '..', 'apps', 'api-gql', 'schema', '*.graphqls'));
const schemaDir = resolve(join(process.cwd(), '..', '..', 'apps', 'api-gql', 'schema', '*.graphqls'))

const config: CodegenConfig = {
config: {
Expand All @@ -21,6 +22,6 @@ const config: CodegenConfig = {
},
},
},
};
}

export default config;
export default config
136 changes: 69 additions & 67 deletions frontend/dashboard/src/api/overlays/chat.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,73 @@
import { useQueryClient, useQuery, useMutation } from '@tanstack/vue-query';
import type {
Settings,
UpdateRequest,
GetAllResponse,
} from '@twir/api/messages/overlays_chat/overlays_chat';
import { unref } from 'vue';
import type { MaybeRef } from 'vue';
import { useQuery } from '@urql/vue'
import { createGlobalState } from '@vueuse/core'

import { protectedApiClient } from '@/api/twirp.js';
import { useMutation } from '@/composables/use-mutation'
import { graphql } from '@/gql'

export const useChatOverlayManager = () => {
const queryClient = useQueryClient();
const queryKey = 'chatOverlay';
const cacheKey = ['chatOverlays']

return {
useGet: (id: MaybeRef<string>) => useQuery({
queryKey: [queryKey, id],
queryFn: async (): Promise<Settings | null> => {
try {
const call = await protectedApiClient.overlayChatGet({
id: unref(id),
});
return call.response;
} catch {
return null;
export const useChatOverlayApi = createGlobalState(() => {
const useOverlaysQuery = () => useQuery({
query: graphql(`
query UseOverlaysData {
chatOverlays {
id
messageHideTimeout
messageShowDelay
preset
fontSize
hideCommands
hideBots
fontFamily
showBadges
showAnnounceBadge
textShadowColor
textShadowSize
chatBackgroundColor
direction
fontWeight
fontStyle
paddingContainer
animation
}
},
}),
useGetAll: () => useQuery({
queryKey: [queryKey],
queryFn: async (): Promise<GetAllResponse> => {
const call = await protectedApiClient.overlayChatGetAll({});
return call.response;
},
}),
useCreate: () => useMutation({
mutationKey: ['chatOverlayCreate'],
mutationFn: async (opts: MaybeRef<Settings>) => {
const data = unref(opts);
const call = await protectedApiClient.overlayChatCreate(data);
return call.response;
},
onSuccess: async () => {
await queryClient.invalidateQueries([queryKey]);
},
}),
useUpdate: () => useMutation({
mutationKey: ['chatOverlayUpdate'],
mutationFn: async (opts: MaybeRef<UpdateRequest>) => {
const data = unref(opts);
await protectedApiClient.overlayChatUpdate(data);
},
onSuccess: async (_, opts) => {
const data = unref(opts);
await queryClient.invalidateQueries([queryKey, data.id]);
},
}),
useDelete: () => useMutation({
mutationKey: ['chatOverlayDelete'],
mutationFn: async (id: MaybeRef<string>) => {
await protectedApiClient.overlayChatDelete({
id: unref(id),
});
},
onSuccess: async () => {
await queryClient.invalidateQueries([queryKey]);
},
}),
};
};
}
`),
context: {
additionalTypenames: cacheKey,
},
})

const useOverlayDelete = () => useMutation(
graphql(`
mutation DeleteOverlay($id: String!) {
chatOverlayDelete(id: $id)
}
`),
cacheKey,
)

const useOverlayCreate = () => useMutation(
graphql(`
mutation CreateOverlay($input: ChatOverlayMutateOpts!) {
chatOverlayCreate(opts: $input)
}
`),
cacheKey,
)

const useOverlayUpdate = () => useMutation(
graphql(`
mutation UpdateOverlay($id: String!, $input: ChatOverlayMutateOpts!) {
chatOverlayUpdate(id: $id, opts: $input)
}
`),
cacheKey,
)

return {
useOverlaysQuery,
useOverlayDelete,
useOverlayCreate,
useOverlayUpdate,
}
})
16 changes: 8 additions & 8 deletions frontend/dashboard/src/components/overlays/chat.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<script setup lang="ts">
import { IconMessage } from '@tabler/icons-vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { IconMessage } from '@tabler/icons-vue'
import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router'
import Card from '@/components/overlays/card.vue';
import Card from '@/components/overlays/card.vue'
const { t } = useI18n();
const { t } = useI18n()
const router = useRouter();
const router = useRouter()
</script>

<template>
<card
<Card
:icon="IconMessage"
:icon-stroke="1"
title="Chat"
Expand All @@ -20,5 +20,5 @@ const router = useRouter();
:show-copy="false"
@open-settings="router.push({ name: 'ChatOverlay' })"
>
</card>
</Card>
</template>
Loading

0 comments on commit 99595c2

Please sign in to comment.